From 2c44584c81e994fa9dd802c0dea7441631ecdb3d Mon Sep 17 00:00:00 2001 From: Brian Rogers Date: Tue, 19 Jul 2022 14:11:54 -0600 Subject: [PATCH] adding a create user command --- src/app/Console/Commands/CreateUser.php | 62 +++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 src/app/Console/Commands/CreateUser.php diff --git a/src/app/Console/Commands/CreateUser.php b/src/app/Console/Commands/CreateUser.php new file mode 100644 index 0000000..3858ccd --- /dev/null +++ b/src/app/Console/Commands/CreateUser.php @@ -0,0 +1,62 @@ +option('email')); + + $name = $this->ask("Please provide a name"); + $surname = $this->ask("Please provide a surname"); + + if (empty($email)) { + $email = $this->ask("Please provide an email address"); + } + + if (empty($password)) { + // TODO: have a way to hide the input and do a confirm password input + $password = $this->ask("Please provide a password"); + } + + try { + User::create([ + 'name' => trim($name), + 'surname' => trim($surname), + 'email' => trim($email), + 'password' => Hash::make(trim($password)), + ]); + + $this->info("$email created successfully."); + return 0; + } catch (\Exception $e) { + $this->error('Unable to create your user.'); + $this->line($e->getMessage()); + return 1; + } + } +}