clrghouz/app/Console/Commands/UserMakeAdmin.php

39 lines
698 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()
{
$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'));
}
}