ldc-legaulois/app/Console/Commands/UserCreate.php
2022-02-10 16:14:58 +01:00

50 lines
1.3 KiB
PHP

<?php
namespace App\Console\Commands;
use App\User;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Hash;
class UserCreate extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'user:create';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Create a backend user';
/**
* Execute the console command.
*
* @return integer
*/
public function handle()
{
$firstname = $this->ask('What is the firstname?');
$lastname = $this->ask('What is the lastname?');
$email = $this->ask('What is the email?');
$role = $this->ask('What is the role 1 (SuperAdmin) or 2 (Admin) ?') == '1' ? 1 : 2;
$pwd = $this->secret('What is the password?');
$user = new User();
$user->firstname = $firstname;
$user->lastname = $lastname;
$user->email = $email;
$user->role = $role;
$user->password = Hash::make($pwd);
$user->email_verified_at = date('Y-m-d H:i:s');
$user->saveOrFail();
$this->info('User created.');
return 0;
}
}