Command refactoring - no functional changes
This commit is contained in:
38
app/Console/Commands/UserMakeAdmin.php
Normal file
38
app/Console/Commands/UserMakeAdmin.php
Normal file
@@ -0,0 +1,38 @@
|
||||
<?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()
|
||||
{
|
||||
$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'));
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user