Good afternoon. Please help to perform the removal according to SOLID. While employees are in the office, the office cannot be deleted.
Now the code is simple. How to change it to a more correct one?
public function destroy(int $id): JsonResponse
{
$this->countUser = User::where('office_id', $id)->count();
if ($this->countUser > 0) {
$this->response = [
'message' => 'office not remove!',
];
return response()->error($this->response);
}
$this->item = Model::findOrFail($id);
$this->item->forceDelete();
$this->response = [
'message' => 'office remove!',
'reload' => true,
];
return response()->success($this->response);
}
source https://stackoverflow.com/questions/76707137/laravel-deletion-with-a-condition
No comments:
Post a Comment