validate([ 'search' => ['nullable', 'string', 'max:255'], ]); $filters = ['search' => $validated['search'] ?? null]; $requests = User::query() ->where('type', UserType::Client) ->where('account_requested', true) ->when($filters['search'], fn (Builder $query, string $search) => $query->where(fn (Builder $q) => $q ->where('name', 'like', "%{$search}%") ->orWhere('email', 'like', "%{$search}%"))) ->orderBy('created_at') ->paginate(25) ->withQueryString() ->through(fn (User $client): array => [ 'id' => $client->id, 'name' => $client->name, 'email' => $client->email, 'created_at' => $client->created_at?->toIso8601String(), ]); return Inertia::render('clients/requests', [ 'requests' => $requests->items(), 'pagination' => Pagination::meta($requests), 'filters' => $filters, ]); } public function approve(User $client): RedirectResponse { abort_unless($client->isClient() && $client->account_requested, 404); // The moment a request becomes a client this installation has taken // on, which is where the seat is spent — provisioning deliberately // does not count a pending one, so that a stranger at the // registration form cannot exhaust a paid limit. See SeatAllowance. $this->seats->guardClient(); $client->forceFill([ 'active' => true, 'account_requested' => false, ])->save(); $this->activity->log(Action::ClientApproved, subject: $client); if ($this->settings->get(Setting::EmailNotificationsEnabled) === true) { $client->notify(new ClientAccountApprovedNotification); } return back()->with('success', __('Account request approved.')); } public function deny(User $client): RedirectResponse { abort_unless($client->isClient() && $client->account_requested, 404); $name = $client->name; $email = $client->email; $locale = $client->locale; // A denied request is removed outright (not soft-deleted) so the // person can register again with the same email address. $client->forceDelete(); $this->activity->log(Action::ClientDenied, context: ['name' => $name]); if ($this->settings->get(Setting::EmailNotificationsEnabled) === true) { Notification::route('mail', $email)->notify( (new ClientAccountDeniedNotification($name))->locale($locale ?? app()->getLocale()) ); } return back()->with('success', __('Account request denied.')); } }