ldc-doux/app/Console/Commands/UserCreate.php
2026-10-27 09:12:51 +01:00

49 lines
1.1 KiB
PHP

<?php
namespace App\Console\Commands;
use App\Models\User;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Hash;
class UserCreate extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
#[\Override]
protected $signature = 'user:create';
/**
* The console command description.
*
* @var string
*/
#[\Override]
protected $description = 'Create a backend user';
/**
* Execute the console command.
*
* @return integer
*/
public function handle()
{
$name = $this->ask('What is the name?');
$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->name = $name;
$user->email = $email;
$user->role = $role;
$user->password = Hash::make($pwd);
$user->saveOrFail();
$this->info('User created.');
return 0;
}
}