diff --git a/conf/CreateUser.php b/conf/CreateUser.php new file mode 100644 index 0000000..e4a3fcc --- /dev/null +++ b/conf/CreateUser.php @@ -0,0 +1,63 @@ + ['required', 'min:4', 'unique:users,name'], + 'email' => ['required', 'email', 'unique:users,email'], + 'password' => ['required', 'min:6'], + ]; + + /** + * Execute the console command. + */ + public function handle(): int + { + $validator = Validator::make([ + 'name' => $this->argument('name'), + 'email' => $this->argument('email'), + 'password' => $this->argument('password'), + ], $this->rules); + + try { + $userData = $validator->validated(); + + $userData['password'] = bcrypt($userData['password']); + $userData['email_verified_at'] = $this->option('unverified') ? NULL : now(); + + User::factory()->create($userData); + + $this->info('User created.'); + + } catch (\Exception $e) { + $this->error("ERROR: {$e->getMessage()} [Code: {$e->getCode()}]"); + return 1; + } + + return 0; + } +}