setDescription('List all system users'); $this->addOption('role', 'r', InputOption::VALUE_OPTIONAL, 'Filter by role name (e.g. administrator, developer, accessor)'); } public function handle(): int { $query = User::query()->with('role'); $role_name = $this->input->getOption('role'); if ($role_name) { $query->whereHas('role', fn ($q) => $q->where('name', $role_name)); } $users = $query->orderBy('id')->get(); if ($users->isEmpty()) { $this->info('No users found.'); return 0; } $rows = $users->map(fn (User $u) => [ $u->id, $u->username, $u->email, $u->role?->name ?? '-', $this->formatStatus($u->status), $u->created_at?->toDateTimeString(), ])->toArray(); $this->table( ['ID', 'Username', 'Email', 'Role', 'Status', 'Created At'], $rows, ); $this->info(sprintf('Total: %d user(s)', count($rows))); return 0; } private function formatStatus(int $status): string { return match ($status) { 1 => 'enabled', 0 => 'disabled', default => 'unknown', }; } }