/
evo
/
docviz
Обзор
Документация
Войти
/
evo
/
docviz
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
main
app/Console/Commands/ListUsers.php
62 строки
1 KB
evo
Initial commit
04 фев 2026, 17:00
04 фев 2026, 17:00
6132ae5
Код
Авторство
О чём код?
<?php namespace App\Console\Commands; use Illuminate\Console\Command; use App\Models\User; class ListUsers extends Command { /** * The name and signature of the console command. * * @var string */ protected $signature = 'user:list {--role=}'; /** * The console command description. * * @var string */ protected $description = 'List all users or filter by role'; /** * Execute the console command. */ public function handle() { $role = $this->option('role'); $query = User::query(); if ($role) { $query->where('role', $role); $this->info("Users with role: {$role}"); } else { $this->info('All users:'); } $users = $query->orderBy('id')->get(); if ($users->isEmpty()) { $this->warn('No users found.'); return 0; } $this->table( ['ID', 'Name', 'Email', 'Role', 'Created'], $users->map(fn($user) => [ $user->id, $user->name, $user->email, $user->role, $user->created_at->format('Y-m-d H:i'), ]) ); $this->info("Total: {$users->count()} user(s)"); return 0; } }