where('email', $this->argument('email'))->first(); if (! $user) { $this->error("No local user with email [{$this->argument('email')}]."); $this->line('Local accounts are created on first login. Ask them to sign in once, then re-run this.'); return self::FAILURE; } $role = $this->argument('role') ?? select( label: 'Which role?', options: Role::query()->pluck('name', 'name')->all(), ); if (! Role::query()->where('name', $role)->exists()) { $this->error("No role named [{$role}]. Run `php artisan permissions:sync` first."); return self::FAILURE; } match (true) { (bool) $this->option('revoke') => $user->removeRole($role), (bool) $this->option('only') => $user->syncRoles([$role]), default => $user->assignRole($role), }; $this->info(sprintf( '%s now has roles: %s', $user->email, $user->fresh()->roles->pluck('name')->implode(', ') ?: '(none)', )); return self::SUCCESS; } }