select('users.*') ->selectRaw('COUNT(DISTINCT(subusers.id)) as subuser_of_count') ->selectRaw('COUNT(DISTINCT(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); return view('admin.users.index', ['users' => $users]); } /** * Display new user page. */ public function create(): View { return view('admin.users.new', [ 'languages' => $this->getAvailableLanguages(true), ]); } /** * Display user view page. */ public function view(User $user): View { return view('admin.users.view', [ 'user' => $user, 'languages' => $this->getAvailableLanguages(true), ]); } /** * Delete a user from the system. * * @throws \Exception * @throws \Pterodactyl\Exceptions\DisplayException */ public function delete(Request $request, User $user): RedirectResponse { if ($request->user()->id === $user->id) { throw new DisplayException($this->translator->get('admin/user.exceptions.user_has_servers')); } $this->deletionService->handle($user); return redirect()->route('admin.users'); } /** * Create a user. * * @throws \Exception * @throws \Throwable */ public function store(NewUserFormRequest $request): RedirectResponse { $user = $this->creationService->handle($request->normalize()); $this->alert->success($this->translator->get('admin/user.notices.account_created'))->flash(); return redirect()->route('admin.users.view', $user->id); } /** * Update a user on the system. * * @throws \Pterodactyl\Exceptions\Model\DataValidationException * @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException */ public function update(UserFormRequest $request, User $user): RedirectResponse { $this->updateService ->setUserLevel(User::USER_LEVEL_ADMIN) ->handle($user, $request->normalize()); $this->alert->success(trans('admin/user.notices.account_updated'))->flash(); return redirect()->route('admin.users.view', $user->id); } /** * Get a JSON response of users on the system. */ public function json(Request $request): Model|LengthAwarePaginator { // Handle single user requests. if ($request->query('user_id')) { return User::query()->findOrFail($request->input('user_id')); } return QueryBuilder::for(User::query())->allowedFilters(['email'])->paginate(25); } }