/
dimamir
/
coolify
Обзор
Документация
Войти
/
dimamir
/
coolify
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
app/Console/Commands/AdminRemoveUser.php
56 строк
1 KB
Thijmen
Fix styling
10 июн 2024, 23:43
10 июн 2024, 23:43
d86274c
Код
Авторство
О чём код?
<?php namespace App\Console\Commands; use App\Models\User; use Illuminate\Console\Command; class AdminRemoveUser extends Command { /** * The name and signature of the console command. * * @var string */ protected $signature = 'admin:remove-user {email}'; /** * The console command description. * * @var string */ protected $description = 'Remove User from database'; /** * Execute the console command. */ public function handle() { try { $email = $this->argument('email'); $confirm = $this->confirm('Are you sure you want to remove user with email: '.$email.'?'); if (! $confirm) { $this->info('User removal cancelled.'); return; } $this->info("Removing user with email: $email"); $user = User::whereEmail($email)->firstOrFail(); $teams = $user->teams; foreach ($teams as $team) { if ($team->members->count() > 1) { $this->error('User is a member of a team with more than one member. Please remove user from team first.'); return; } $team->delete(); } $user->delete(); } catch (\Exception $e) { $this->error('Failed to remove user.'); $this->error($e->getMessage()); return; } } }