refactor: Refactor della creazione di un utente Admin usando l'azione di Fortify

This commit is contained in:
Maicol Battistini 2023-12-06 21:29:47 +01:00
parent e409fcb0d2
commit af1109c873
No known key found for this signature in database
1 changed files with 3 additions and 5 deletions

View File

@ -2,6 +2,7 @@
namespace App\Console\Commands;
use App\Actions\Fortify\CreateNewUser;
use App\Models\User;
use Illuminate\Console\Command;
use Illuminate\Support\Str;
@ -20,16 +21,13 @@ class CreateAdminUserCommand extends Command
$username = text('Username', required: true);
$email = text('Email', required: true);
$password = password('Password', required: true);
$password_confirmation = password('Confirm Password', required: true);
$this->table(['Username', 'Email', 'Password'], [[$username, $email, '********']]);
if (confirm('Are you sure you want to create this user?')) {
$user = new User();
$user->username = $username;
$user->email = $email;
$user->password = $password;
$user = app(CreateNewUser::class)->create(compact('username', 'email', 'password', 'password_confirmation'));
$user->email_verified_at = now();
$user->remember_token = Str::random(10);
$user->save();
$this->info('Admin user created successfully');