aboutsummaryrefslogtreecommitdiffhomepage
path: root/api/Users/Console/AddUserCommand.php
diff options
context:
space:
mode:
Diffstat (limited to 'api/Users/Console/AddUserCommand.php')
-rw-r--r--api/Users/Console/AddUserCommand.php59
1 files changed, 59 insertions, 0 deletions
diff --git a/api/Users/Console/AddUserCommand.php b/api/Users/Console/AddUserCommand.php
new file mode 100644
index 0000000..021d5aa
--- /dev/null
+++ b/api/Users/Console/AddUserCommand.php
@@ -0,0 +1,59 @@
+<?php
+
+namespace Api\Users\Console;
+
+use Api\Users\Repositories\UserRepository;
+use Illuminate\Console\Command;
+
+class AddUserCommand extends Command
+{
+ /**
+ * The name and signature of the console command.
+ *
+ * @var string
+ */
+ protected $signature = 'users:add {name} {email} {password}';
+
+ /**
+ * The console command description.
+ *
+ * @var string
+ */
+ protected $description = 'Adds a new user';
+
+ /**
+ * User repository to persist user in database
+ *
+ * @var UserRepository
+ */
+ protected $userRepository;
+
+ /**
+ * Create a new command instance.
+ *
+ * @param UserRepository $userRepository
+ * @return void
+ */
+ public function __construct(UserRepository $userRepository)
+ {
+ parent::__construct();
+
+ $this->userRepository = $userRepository;
+ }
+
+ /**
+ * Execute the console command.
+ *
+ * @return mixed
+ */
+ public function handle()
+ {
+ $user = $this->userRepository->create([
+ 'name' => $this->argument('name'),
+ 'email' => $this->argument('email'),
+ 'password' => $this->argument('password')
+ ]);
+
+ $this->info(sprintf('A user was created with ID %s', $user->id));
+ }
+} \ No newline at end of file