Add checks to prevent orphaned records
This commit is contained in:
@@ -170,11 +170,18 @@ class DepreciationsController extends AdminController {
|
||||
return Redirect::to('admin/settings/depreciations')->with('error', Lang::get('admin/depreciations/message.not_found'));
|
||||
}
|
||||
|
||||
// Delete the depreciation
|
||||
$depreciation->delete();
|
||||
if ($depreciation->has_models() > 0) {
|
||||
|
||||
// Redirect to the asset management page
|
||||
return Redirect::to('admin/settings/depreciations')->with('error', Lang::get('admin/depreciations/message.assoc_users'));
|
||||
} else {
|
||||
|
||||
$depreciation->delete();
|
||||
|
||||
// Redirect to the depreciations management page
|
||||
return Redirect::to('admin/settings/depreciations')->with('success', Lang::get('admin/depreciations/message.delete.success'));
|
||||
}
|
||||
|
||||
// Redirect to the depreciations management page
|
||||
return Redirect::to('admin/settings/depreciations')->with('success', Lang::get('admin/depreciations/message.delete.success'));
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -175,11 +175,21 @@ class LocationsController extends AdminController {
|
||||
return Redirect::to('admin/settings/locations')->with('error', Lang::get('admin/locations/message.not_found'));
|
||||
}
|
||||
|
||||
// Delete the location
|
||||
$location->delete();
|
||||
|
||||
// Redirect to the locations management page
|
||||
return Redirect::to('admin/settings/locations')->with('success', Lang::get('admin/locations/message.delete.success'));
|
||||
if ($location->has_users() > 0) {
|
||||
|
||||
// Redirect to the asset management page
|
||||
return Redirect::to('admin/settings/locations')->with('error', Lang::get('admin/locations/message.assoc_users'));
|
||||
} else {
|
||||
|
||||
$location->delete();
|
||||
|
||||
// Redirect to the locations management page
|
||||
return Redirect::to('admin/settings/locations')->with('success', Lang::get('admin/locations/message.delete.success'));
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user