Use the role\'s code} {--f|force : Force the operation to run and ignore production warnings and confirmation questions.}'; /** * @var string The console command description. */ protected $description = 'Creates a backend user.'; /** * Execute the console command. */ public function handle(): int { $email = $this->argument('email'); if ( Config::get('app.env', 'production') !== 'local' && !$this->option('force') && !$this->confirmWithInput("CAUTION, currently working with non-local data. Please confirm the user email address", $email) ) { return 1; } if (User::where('email', $email)->exists()) { $this->error('A user with that email already exists.'); return 1; } $data = [ 'email' => $email, 'password' => $this->option('password') ?: $this->secret('Password'), 'first_name' => $this->option('fname') ?: $this->ask('First name', ''), 'last_name' => $this->option('lname') ?: $this->ask('Last name', ''), 'role_id' => ( UserRole::where( 'code', $this->option('role') ?: $this->choice( 'Role', UserRole::lists('name', 'code') ) )->firstOrFail() )->id, ]; $data['password_confirmation'] = $data['password']; $user = User::create([ 'first_name' => $data['first_name'], 'last_name' => $data['last_name'], 'login' => $data['email'], 'email' => $data['email'], 'role_id' => $data['role_id'], 'password' => $data['password'], 'password_confirmation' => $data['password'], ]); $this->info("User {$user->email} created successfully with the {$role->name} role."); return 0; } }