This commit is contained in:
deploy-bot committed 2026-12-05 19:00:02 +00:00
commit 4769402b1b
298 files changed
+20934

No files matched your search

+49
View File
@@ -0,0 +1,49 @@
<?php
namespace IriksIT\Manager\Console;
use Illuminate\Console\Command;
/**
* The accounts of the manager, with their groups. `--json` for scripts and agents.
*
* php artisan manager:users [--json]
*/
class UserListCommand extends Command
{
protected $signature = 'manager:users {--json : Print JSON}';
protected $description = 'List the accounts of the manager with their groups';
public function handle(): int
{
$model = config('manager.user_model');
$rows = [];
foreach ($model::query()->with('managerGroups')->orderBy('id')->get() as $user) {
$primary = $user->managerPrimaryGroup();
$rows[] = [
'id' => $user->getKey(),
'name' => (string) $user->name,
'email' => (string) $user->email,
'super_admin' => $user->isManagerSuperAdmin(),
'primary_group' => $primary?->name,
'groups' => $user->managerGroups->pluck('name')->sort()->values()->all(),
];
}
if ($this->option('json')) {
$this->line(json_encode($rows, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES));
return self::SUCCESS;
}
$this->table(['Id', 'Name', 'Email', 'Super admin', 'Primary group', 'Groups'], array_map(
fn ($row) => [$row['id'], $row['name'], $row['email'], $row['super_admin'] ? 'yes' : '', $row['primary_group'] ?? '', implode(', ', $row['groups'])],
$rows,
));
return self::SUCCESS;
}
}