meobda-website/app/Console/Commands/CreateUser.php

59 lines
1.4 KiB
PHP

<?php
namespace App\Console\Commands;
use App\Actions\Fortify\CreateNewUser;
use Illuminate\Console\Command;
use function Laravel\Prompts\password;
use function Laravel\Prompts\text;
class CreateUser extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'app:create-user';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Creates a user';
/**
* Execute the console command.
*/
public function handle(CreateNewUser $creator)
{
$name = text(
label: 'What is the new user\'s name?',
validate: ['name' => 'required|min:3'],
);
$email = text(
label: 'What is the new user\'s email?',
validate: ['email' => 'required|email|unique:users,email'],
);
$password = password(
label: 'Desired password: ',
validate: ['password' => 'required|min:8'],
);
$password_confirmation = password(
label: 'Confirm password: ',
validate: ['password_confirmation' => 'required'],
);
$newUser = $creator->create([
'name' => $name,
'email' => $email,
'password' => $password,
'password_confirmation' => $password_confirmation,
]);
$this->info('User created successfully.');
}
}