diff options
author | Marvin Borner | 2018-08-24 13:17:32 +0200 |
---|---|---|
committer | Marvin Borner | 2018-08-24 13:17:32 +0200 |
commit | 0ee38e98532a9daf7ba08ab65b7f73d6505e0aea (patch) | |
tree | 6ff916179bb4ebe14369ea99b84109dc6e52ba13 /api/Posts/Console | |
parent | 3045cb39be8b9c9cb3ca6ed643ccceac0042f0c0 (diff) |
Began API for posts
Diffstat (limited to 'api/Posts/Console')
-rw-r--r-- | api/Posts/Console/AddPostCommand.php | 59 |
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 |