2024-06-07 12:44:51 +05:30
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Http\Controllers\Admin;
|
|
|
|
|
|
|
|
|
|
use App\Http\Controllers\Controller;
|
|
|
|
|
use App\Models\ManageState;
|
|
|
|
|
use Illuminate\Http\Request;
|
|
|
|
|
use Exception;
|
|
|
|
|
use Illuminate\Support\Facades\Log;
|
|
|
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
|
|
|
|
|
|
class ManageLocationController extends Controller
|
|
|
|
|
{
|
2024-06-17 13:41:03 +05:30
|
|
|
|
2024-06-07 12:44:51 +05:30
|
|
|
/*
|
|
|
|
|
Created By : Sayali parab
|
|
|
|
|
Created at : 07 June 2024
|
|
|
|
|
Use : To get the page.
|
|
|
|
|
*/
|
|
|
|
|
public function index()
|
|
|
|
|
{
|
2024-06-17 13:41:03 +05:30
|
|
|
$location = ManageState::orderBy('id', 'asc')->get();
|
2024-06-07 12:44:51 +05:30
|
|
|
return view('Admin.pages.manage_states.manage_states', compact('location'));
|
|
|
|
|
}
|
2024-06-17 13:41:03 +05:30
|
|
|
/*
|
2024-06-07 12:44:51 +05:30
|
|
|
Created By : Sayali parab
|
|
|
|
|
Created at : 07 June 2024
|
|
|
|
|
Use : To store the location.
|
|
|
|
|
*/
|
|
|
|
|
|
2024-06-17 13:41:03 +05:30
|
|
|
|
2024-06-07 12:44:51 +05:30
|
|
|
public function store(Request $request)
|
2024-06-17 13:41:03 +05:30
|
|
|
{
|
|
|
|
|
$request->validate([
|
|
|
|
|
'location_name' => 'required|string|max:255'
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
if (ManageState::where('name', $request->location_name)->exists()) {
|
|
|
|
|
return response()->json(['success' => false, 'error' => 'Location name already exists', 'status' => 422]);
|
|
|
|
|
}
|
2024-06-07 13:24:32 +05:30
|
|
|
|
|
|
|
|
|
2024-06-17 13:41:03 +05:30
|
|
|
$location = new ManageState();
|
|
|
|
|
$location->name = $request->location_name;
|
|
|
|
|
$location->save();
|
2024-06-07 13:24:32 +05:30
|
|
|
|
2024-06-17 13:41:03 +05:30
|
|
|
return response()->json(['success' => true, 'status' => 200]);
|
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
|
return response()->json(['success' => false, 'error' => $e->getMessage(), 'status' => 500]);
|
|
|
|
|
}
|
2024-06-07 12:44:51 +05:30
|
|
|
}
|
2024-06-07 13:24:32 +05:30
|
|
|
|
2024-06-07 12:44:51 +05:30
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
Created By : Sayali parab
|
|
|
|
|
Created at : 07 June 2024
|
|
|
|
|
Use : To change status.
|
|
|
|
|
*/
|
2024-06-17 13:41:03 +05:30
|
|
|
public function change_location_status(Request $request)
|
2024-06-07 12:44:51 +05:30
|
|
|
{
|
2024-06-17 13:41:03 +05:30
|
|
|
|
2024-06-07 12:44:51 +05:30
|
|
|
try {
|
|
|
|
|
DB::beginTransaction();
|
|
|
|
|
$status = ManageState::find($request->location_id);
|
|
|
|
|
$status->is_active = $request->status;
|
|
|
|
|
$status->save();
|
|
|
|
|
// return response()->json(['status' => 200]);
|
|
|
|
|
DB::commit();
|
|
|
|
|
|
|
|
|
|
return jsonResponseWithSuccessMessage(__('success.update_data'));
|
|
|
|
|
} catch (Exception $e) {
|
|
|
|
|
Log::error("Update Status function Load Failed " . $e->getMessage());
|
|
|
|
|
return jsonResponseWithErrorMessage(__('auth.something_went_wrong'), 500);
|
|
|
|
|
}
|
2024-06-17 13:41:03 +05:30
|
|
|
}
|
2024-06-07 12:44:51 +05:30
|
|
|
|
|
|
|
|
|
2024-06-17 13:41:03 +05:30
|
|
|
/*
|
2024-06-07 12:44:51 +05:30
|
|
|
Created By : Sayali parab
|
|
|
|
|
Created at : 07 June 2024
|
|
|
|
|
Use : To delete location.
|
|
|
|
|
*/
|
|
|
|
|
public function delete_location($id)
|
|
|
|
|
{
|
|
|
|
|
|
2024-06-17 13:41:03 +05:30
|
|
|
|
2024-06-07 12:44:51 +05:30
|
|
|
try {
|
|
|
|
|
DB::beginTransaction();
|
|
|
|
|
|
|
|
|
|
$passport = ManageState::find($id);
|
|
|
|
|
$passport->delete();
|
|
|
|
|
|
|
|
|
|
DB::commit();
|
|
|
|
|
|
|
|
|
|
return response()->json(['success' => true, 'status' => 200]);
|
|
|
|
|
} catch (Exception $e) {
|
|
|
|
|
DB::rollBack();
|
|
|
|
|
Log::error("delete_location function Load Failed " . $e->getMessage());
|
|
|
|
|
return response()->json(['success' => false, 'status' => 500, 'message' => __('auth.something_went_wrong')]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-07 13:24:32 +05:30
|
|
|
|
2024-06-17 13:41:03 +05:30
|
|
|
/*
|
2024-06-07 12:44:51 +05:30
|
|
|
Created By : Sayali parab
|
|
|
|
|
Created at : 07 June 2024
|
|
|
|
|
Use : To update location.
|
2024-06-17 13:41:03 +05:30
|
|
|
*/
|
2024-06-26 19:12:45 +05:30
|
|
|
|
2024-06-07 13:24:32 +05:30
|
|
|
public function update(Request $request)
|
|
|
|
|
{
|
2024-06-07 12:44:51 +05:30
|
|
|
try {
|
|
|
|
|
DB::beginTransaction();
|
2024-06-26 19:12:45 +05:30
|
|
|
|
|
|
|
|
// Check if the location name already exists, excluding the current location
|
|
|
|
|
if (ManageState::where('name', $request->location_name)->where('id', '!=', $request->id)->exists()) {
|
|
|
|
|
return response()->json(['success' => false, 'error' => 'Location name already exists', 'status' => 422]);
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-07 12:44:51 +05:30
|
|
|
$location_data = ManageState::find($request->id);
|
|
|
|
|
$location_data->name = $request->location_name;
|
|
|
|
|
$location_data->save();
|
2024-06-26 19:12:45 +05:30
|
|
|
|
2024-06-07 12:44:51 +05:30
|
|
|
DB::commit();
|
2024-06-26 19:12:45 +05:30
|
|
|
|
|
|
|
|
return response()->json(['success' => true, 'message' => __('success.update_data'), 'status' => 200]);
|
2024-06-07 12:44:51 +05:30
|
|
|
} catch (Exception $e) {
|
|
|
|
|
DB::rollBack();
|
|
|
|
|
Log::error("Failed to update location: " . $e->getMessage());
|
2024-06-26 19:12:45 +05:30
|
|
|
return response()->json(['success' => false, 'error' => __('auth.something_went_wrong'), 'status' => 500]);
|
2024-06-07 12:44:51 +05:30
|
|
|
}
|
|
|
|
|
}
|
2024-06-26 19:12:45 +05:30
|
|
|
|
|
|
|
|
|
2024-06-07 12:44:51 +05:30
|
|
|
}
|