diff --git a/app/Http/Controllers/Api/UsersController.php b/app/Http/Controllers/Api/UsersController.php index f2f2f28b80..0faa541243 100644 --- a/app/Http/Controllers/Api/UsersController.php +++ b/app/Http/Controllers/Api/UsersController.php @@ -416,11 +416,14 @@ class UsersController extends Controller $this->authorize('view', User::class); $user = User::withCount('assets as assets_count', 'licenses as licenses_count', 'accessories as accessories_count', 'consumables as consumables_count', 'managesUsers as manages_users_count', 'managedLocations as manages_locations_count'); - $user = Company::scopeCompanyables($user)->find($id); - $this->authorize('view', $user); + if ($user = Company::scopeCompanyables($user)->find($id)) { + $this->authorize('view', $user); + return (new UsersTransformer)->transformUser($user); + } + + return response()->json(Helper::formatStandardApiResponse('error', null, trans('admin/users/message.user_not_found', compact('id')))); - return (new UsersTransformer)->transformUser($user); }