-
app/Console/Commands/UserAdmin.php
Open in GitHubuse Illuminate\Console\Command; use App\User; class UserAdmin extends Command { protected $signature = 'user:admin {id}'; protected $description = 'Make a user an admin, or remove admin privileges.'; public function __construct() { parent::__construct(); } public function handle() { $id = $this->argument('id'); $user = User::whereUsername($id)->orWhere('id', $id)->first(); if(!$user) { $this->error('Could not find any user with that username or id.'); exit; } $this->info('Found username: ' . $user->username); $state = $user->is_admin ? 'Remove admin privileges from this user?' : 'Add admin privileges to this user?'; $confirmed = $this->confirm($state); if(!$confirmed) { exit; } $user->is_admin = !$user->is_admin; $user->save(); $this->info('Successfully changed permissions!'); } }