From 054e65b78fddb3bc37090882a62e8e49442f154f Mon Sep 17 00:00:00 2001 From: Dane Everitt Date: Fri, 17 Feb 2017 19:28:23 -0500 Subject: [PATCH] Fix user deletion --- app/Repositories/UserRepository.php | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/app/Repositories/UserRepository.php b/app/Repositories/UserRepository.php index 5ab2edbbf..c59637783 100644 --- a/app/Repositories/UserRepository.php +++ b/app/Repositories/UserRepository.php @@ -165,7 +165,7 @@ class UserRepository */ public function delete($id) { - if (Models\Server::where('owner', $id)->count() > 0) { + if (Models\Server::where('owner_id', $id)->count() > 0) { throw new DisplayException('Cannot delete a user with active servers attached to thier account.'); } @@ -177,10 +177,15 @@ class UserRepository DB::beginTransaction(); try { - Models\Permission::where('user_id', $id)->delete(); - Models\Subuser::where('user_id', $id)->delete(); - Models\User::destroy($id); + foreach(Models\Subuser::with('permissions')->where('user_id', $id)->get() as &$subuser) { + foreach($subuser->permissions as &$permission) { + $permission->delete(); + } + $subuser->delete(); + } + + Models\User::destroy($id); DB::commit(); return true;