This commit is contained in:
sayliraut
2024-06-17 13:41:03 +05:30
parent 4c0a8b76d8
commit 059e085ff4

View File

@@ -11,7 +11,7 @@ use Illuminate\Support\Facades\DB;
class ManageLocationController extends Controller
{
/*
Created By : Sayali parab
Created at : 07 June 2024
@@ -19,37 +19,37 @@ class ManageLocationController extends Controller
*/
public function index()
{
$location = ManageState::latest()->get();
$location = ManageState::orderBy('id', 'asc')->get();
return view('Admin.pages.manage_states.manage_states', compact('location'));
}
/*
/*
Created By : Sayali parab
Created at : 07 June 2024
Use : To store the location.
*/
public function store(Request $request)
{
$request->validate([
'location_name' => 'required|string|max:255'
]);
{
$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]);
try {
if (ManageState::where('name', $request->location_name)->exists()) {
return response()->json(['success' => false, 'error' => 'Location name already exists', 'status' => 422]);
}
$location = new ManageState();
$location->name = $request->location_name;
$location->save();
return response()->json(['success' => true, 'status' => 200]);
} catch (\Exception $e) {
return response()->json(['success' => false, 'error' => $e->getMessage(), 'status' => 500]);
}
$location = new ManageState();
$location->name = $request->location_name;
$location->save();
return response()->json(['success' => true, 'status' => 200]);
} catch (\Exception $e) {
return response()->json(['success' => false, 'error' => $e->getMessage(), 'status' => 500]);
}
}
/*
@@ -57,9 +57,9 @@ class ManageLocationController extends Controller
Created at : 07 June 2024
Use : To change status.
*/
public function change_location_status(Request $request)
public function change_location_status(Request $request)
{
try {
DB::beginTransaction();
$status = ManageState::find($request->location_id);
@@ -69,16 +69,14 @@ class ManageLocationController extends Controller
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);
}
}
}
/*
/*
Created By : Sayali parab
Created at : 07 June 2024
Use : To delete location.
@@ -86,7 +84,7 @@ class ManageLocationController extends Controller
public function delete_location($id)
{
try {
DB::beginTransaction();
@@ -96,7 +94,6 @@ class ManageLocationController extends Controller
DB::commit();
return response()->json(['success' => true, 'status' => 200]);
} catch (Exception $e) {
DB::rollBack();
Log::error("delete_location function Load Failed " . $e->getMessage());
@@ -105,31 +102,29 @@ class ManageLocationController extends Controller
}
/*
/*
Created By : Sayali parab
Created at : 07 June 2024
Use : To update location.
*/
*/
public function update(Request $request)
{
try {
DB::beginTransaction();
$location_data = ManageState::find($request->id);
$location_data->name = $request->location_name;
$location_data->save();
DB::commit();
return jsonResponseWithSuccessMessage(__('success.update_data'));
} catch (Exception $e) {
DB::rollBack();
Log::error("Failed to update location: " . $e->getMessage());
return jsonResponseWithErrorMessage(__('auth.something_went_wrong'), 500);
}
}
}