Cleaned up controller code a bit

Signed-off-by: snipe <snipe@snipe.net>
This commit is contained in:
snipe 2024-06-22 19:33:36 +01:00
parent 1d26ccac4e
commit 9e59bd5687

View file

@ -521,13 +521,11 @@ class UsersController extends Controller
public function destroy(DeleteUserRequest $request, $id)
{
$this->authorize('delete', User::class);
$user = User::with('assets', 'assets.model', 'consumables', 'accessories', 'licenses', 'userloc')->withTrashed()->find($id);
$this->authorize('delete', $user);
if ($user = User::withTrashed()->find($id)) {
$this->authorize('delete', $user);
if ($user) {
if ($user->delete()) {
// Remove the user's avatar if they have one
@ -541,6 +539,7 @@ class UsersController extends Controller
return response()->json(Helper::formatStandardApiResponse('success', null, trans('admin/users/message.success.delete')));
}
return response()->json(Helper::formatStandardApiResponse('error', null, trans('admin/users/message.error.delete')));
}