ldc-supportweb/app/Console/Commands/CreateUser.php
2022-03-29 16:57:54 +02:00

50 lines
1.1 KiB
PHP

<?php
namespace App\Console\Commands;
use App\Enums\Role;
use App\Models\User;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Hash;
class CreateUser extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'create:user';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Create a user';
/**
* Execute the console command.
*
* @return integer
*/
public function handle()
{
$name = $this->ask('What is the name?');
$email = $this->ask('What is the email?');
$pwd = $this->secret('What is the password?');
$user = new User();
$user->name = $name;
$user->email = $email;
if ($this->confirm('Is the user an admin?')) {
$user->role = Role::admin();
} else {
$user->role = Role::client();
}
$user->password = Hash::make($pwd);
$user->save();
$this->info('User created.');
return 0;
}
}