This commit is contained in:
sayaliparab
2024-06-26 19:12:45 +05:30
parent d83916ca03
commit 0c9159099a
2 changed files with 27 additions and 14 deletions

View File

@@ -107,24 +107,30 @@ class ManageLocationController extends Controller
Created at : 07 June 2024
Use : To update location.
*/
public function update(Request $request)
{
try {
DB::beginTransaction();
// 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]);
}
$location_data = ManageState::find($request->id);
$location_data->name = $request->location_name;
$location_data->save();
DB::commit();
return jsonResponseWithSuccessMessage(__('success.update_data'));
return response()->json(['success' => true, 'message' => __('success.update_data'), 'status' => 200]);
} catch (Exception $e) {
DB::rollBack();
Log::error("Failed to update location: " . $e->getMessage());
return jsonResponseWithErrorMessage(__('auth.something_went_wrong'), 500);
return response()->json(['success' => false, 'error' => __('auth.something_went_wrong'), 'status' => 500]);
}
}
}

View File

@@ -6,6 +6,7 @@ $(document).on("click", ".edit_location_value", function (e) {
});
$('#edit_location').validate({
rules: {
location_name: {
@@ -21,7 +22,7 @@ $('#edit_location').validate({
submitHandler: function (form) {
var formData = new FormData(form);
$('#update_passport_btn').text('Please wait...');
$('#update_passport_btn').attr('disabled', true);
$('#update_passport_btn').attr('disabled', true);
let base_url = url_path;
$.ajax({
url: base_url + '/update_location',
@@ -30,13 +31,16 @@ $('#edit_location').validate({
processData: false,
contentType: false,
success: function(result) {
if (result.status_code == 200) {
if (result.status === 200) {
toastr.success('Location Updated successfully');
setTimeout(function() {
window.location.href = base_url + "/manage_location";
}, 2000);
} else {
}
else if (result.status === 422 && result.error === 'Location name already exists') {
toastr.error('Location name already exists');
}
else {
toastr.error('Something Went Wrong');
setTimeout(function() {
window.location.href = base_url + "/manage_location";
@@ -45,8 +49,11 @@ $('#edit_location').validate({
$('#update_passport_btn').attr('disabled', false);
$('#update_passport_btn').text('Submit');
},
error: function(xhr, status, error) {
toastr.error('Something Went Wrong');
$('#update_passport_btn').attr('disabled', false);
$('#update_passport_btn').text('Submit');
}
});
$('#update_passport_btn').attr('disabled', false);
$('#update_passport_btn').text('Submit');
}
});
});