From 94ce8cad64751eb8583c312b559ed11805463192 Mon Sep 17 00:00:00 2001 From: snipe Date: Wed, 11 Dec 2019 14:43:46 -0800 Subject: [PATCH] Make sure $user->item exists before trying to count on it --- app/Http/Controllers/Users/UsersController.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/Http/Controllers/Users/UsersController.php b/app/Http/Controllers/Users/UsersController.php index c374f69c09..3cb453b501 100755 --- a/app/Http/Controllers/Users/UsersController.php +++ b/app/Http/Controllers/Users/UsersController.php @@ -324,25 +324,25 @@ class UsersController extends Controller ->with('error', 'We would feel really bad if you deleted yourself, please reconsider.'); } - if (($assetsCount = $user->assets()->count()) > 0) { + if (($user->assets()) && (($assetsCount = $user->assets()->count()) > 0)) { // Redirect to the user management page return redirect()->route('users.index') ->with('error', 'This user still has ' . $assetsCount . ' assets associated with them.'); } - if (($licensesCount = $user->licenses()->count()) > 0) { + if (($user->licenses()) && (($licensesCount = $user->licenses()->count())) > 0) { // Redirect to the user management page return redirect()->route('users.index') ->with('error', 'This user still has ' . $licensesCount . ' licenses associated with them.'); } - if (($accessoriesCount = $user->accessories()->count()) > 0) { + if (($user->accessories()) && (($accessoriesCount = $user->accessories()->count()) > 0)) { // Redirect to the user management page return redirect()->route('users.index') ->with('error', 'This user still has ' . $accessoriesCount . ' accessories associated with them.'); } - if (($managedLocationsCount = $user->managedLocations()->count()) > 0) { + if (($user->managedLocations()) && (($managedLocationsCount = $user->managedLocations()->count())) > 0) { // Redirect to the user management page return redirect()->route('users.index') ->with('error', 'This user still has ' . $managedLocationsCount . ' locations that they manage.');