Correctly show number of servers a user belongs to; closes #2375

This commit is contained in:
Dane Everitt 2020-09-22 20:13:54 -07:00
parent 1b0a6252f1
commit 7f9b21e486
No known key found for this signature in database
GPG key ID: EEA66103B3D71F53

View file

@ -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);