clrghouz/app/Console/Commands/UserMakeAdmin.php

41 lines
728 B
PHP

<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use App\Models\User;
class UserMakeAdmin extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'user:make:admin {email : User Email}';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Make a user a system admin';
/**
* Execute the console command.
*
* @return int
*/
public function handle(): int
{
$o = User::where('email',$this->argument('email'))->firstOrfail();
$o->admin = ! $o->admin;
$o->save();
$this->info(sprintf('User [%s] %s an admin',$o->email,$o->admin ? 'IS' : 'is NOT'));
return self::SUCCESS;
}
}