36 lines
833 B
PHP
Executable File
36 lines
833 B
PHP
Executable File
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Modules\UserManagement\Console;
|
|
|
|
use App\Models\User;
|
|
use Illuminate\Console\Command;
|
|
|
|
final class EnsureAdminCommand extends Command
|
|
{
|
|
protected $signature = 'users:ensure-admin {user=1 : User ID to grant administrator access}';
|
|
|
|
protected $description = 'Ensure a user has Helpdesk administrator and agent access';
|
|
|
|
public function handle(): int
|
|
{
|
|
$user = User::query()->find((int) $this->argument('user'));
|
|
|
|
if ($user === null) {
|
|
$this->error('User not found.');
|
|
|
|
return self::FAILURE;
|
|
}
|
|
|
|
$user->forceFill([
|
|
'helpdesk_admin' => true,
|
|
'helpdesk_agent' => true,
|
|
])->save();
|
|
|
|
$this->info("{$user->name} is now a Helpdesk administrator.");
|
|
|
|
return self::SUCCESS;
|
|
}
|
|
}
|