is_admin && ! User::query()->where('is_admin', true)->whereKeyNot(Auth::id())->exists(); } /** * Delete the currently authenticated user, unless it is the only admin. */ public function deleteUser(Logout $logout): void { $this->validate([ 'password' => $this->currentPasswordRules(), ]); // The admin rows stay locked until the delete, so two admins cannot delete each other's last peer at once. $deleted = DB::transaction(function () use ($logout): bool { User::query()->where('is_admin', true)->lockForUpdate()->get(); if ($this->isLastAdmin()) { return false; } tap(Auth::user(), $logout(...))->delete(); return true; }); if (! $deleted) { $this->addError('password', __('You are the only admin, so this account cannot be deleted.')); return; } $this->redirect('/', navigate: true); } }; ?> @if ($this->isLastAdmin())

{{ __('You are the only admin, so this account cannot be deleted.') }}

@else

{{ __('Once your account is deleted, all of its resources and data will be permanently deleted. Please enter your password to confirm you would like to permanently delete your account.') }}

@endif