aboutsummaryrefslogtreecommitdiffhomepage
path: root/api/Posts/Console
diff options
context:
space:
mode:
authorMarvin Borner2018-08-24 13:17:32 +0200
committerMarvin Borner2018-08-24 13:17:32 +0200
commit0ee38e98532a9daf7ba08ab65b7f73d6505e0aea (patch)
tree6ff916179bb4ebe14369ea99b84109dc6e52ba13 /api/Posts/Console
parent3045cb39be8b9c9cb3ca6ed643ccceac0042f0c0 (diff)
Began API for posts
Diffstat (limited to 'api/Posts/Console')
-rw-r--r--api/Posts/Console/AddPostCommand.php59
1 files changed, 59 insertions, 0 deletions
diff --git a/api/Posts/Console/AddPostCommand.php b/api/Posts/Console/AddPostCommand.php
new file mode 100644
index 0000000..977afb6
--- /dev/null
+++ b/api/Posts/Console/AddPostCommand.php
@@ -0,0 +1,59 @@
+<?php
+
+namespace Api\Posts\Console;
+
+use Api\Posts\Repositories\PostRepository;
+use Illuminate\Console\Command;
+
+class AddPostCommand extends Command
+{
+ /**
+ * The name and signature of the console command.
+ *
+ * @var string
+ */
+ protected $signature = 'posts:add {name} {email} {password}';
+
+ /**
+ * The console command description.
+ *
+ * @var string
+ */
+ protected $description = 'Adds a new post';
+
+ /**
+ * Post repository to persist post in database
+ *
+ * @var PostRepository
+ */
+ protected $postRepository;
+
+ /**
+ * Create a new command instance.
+ *
+ * @param PostRepository $postRepository
+ * @return void
+ */
+ public function __construct(PostRepository $postRepository)
+ {
+ parent::__construct();
+
+ $this->postRepository = $postRepository;
+ }
+
+ /**
+ * Execute the console command.
+ *
+ * @return mixed
+ */
+ public function handle()
+ {
+ $post = $this->postRepository->create([
+ 'name' => $this->argument('name'),
+ 'email' => $this->argument('email'),
+ 'password' => $this->argument('password')
+ ]);
+
+ $this->info(sprintf('A post was created with ID %s', $post->id));
+ }
+} \ No newline at end of file