From 7f9b21e48666fde84af736aeef80623a73359b4b Mon Sep 17 00:00:00 2001 From: Dane Everitt Date: Tue, 22 Sep 2020 20:13:54 -0700 Subject: [PATCH] Correctly show number of servers a user belongs to; closes #2375 --- app/Http/Controllers/Admin/UserController.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/app/Http/Controllers/Admin/UserController.php b/app/Http/Controllers/Admin/UserController.php index 2afbe140..e0b53c34 100644 --- a/app/Http/Controllers/Admin/UserController.php +++ b/app/Http/Controllers/Admin/UserController.php @@ -84,7 +84,14 @@ class UserController extends Controller */ public function index(Request $request) { - $users = QueryBuilder::for(User::query()->withCount('servers')) + $users = QueryBuilder::for( + User::query()->select('users.*') + ->selectRaw('COUNT(subusers.id) as subuser_of_count') + ->selectRaw('COUNT(servers.id) as servers_count') + ->leftJoin('subusers', 'subusers.user_id', '=', 'users.id') + ->leftJoin('servers', 'servers.owner_id', '=', 'users.id') + ->groupBy('users.id') + ) ->allowedFilters(['username', 'email', 'uuid']) ->allowedSorts(['id', 'uuid']) ->paginate(50);