/**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     $repo = App::make(PostRepository::class);
     $faker = App::make(Faker\Generator::class);
     $faker->addProvider(new \DavidBadura\FakerMarkdownGenerator\FakerProvider($faker));
     $categories = [PostCategory::fromString(PostCategory::BLOGPOST), PostCategory::fromString(PostCategory::NEWSPOST)];
     for ($i = 0; $i < 10; $i++) {
         $id = PostId::generate();
         $post = Post::createDraft($id, $faker->sentence, implode($faker->paragraphs(4), "\n"), $faker->randomElement($categories));
         $post->setPublishDate(new Carbon\Carbon());
         $repo->save($post);
     }
 }
 public function store(Request $req, PostRepository $repo)
 {
     //Validate doesn't work?
     // $this->validate($req, [
     //     'title' => 'required|max:255',
     //     'content' => 'required',
     //     'type' => 'in:blog,news',
     //     'publishes_at' => 'date',
     // ]);
     $id = PostId::generate();
     $post = Post::createDraft($id, $req->input('title'), $req->input('content'), PostCategory::fromString($req->input('type')));
     $post->setPublishDate(\Carbon\Carbon::now());
     /// @todo
     $repo->save($post);
     return redirect('/admin/post');
 }
 /** @test */
 public function it_can_only_be_a_blog_or_news_post()
 {
     $this->expectException(\InvalidArgumentException::class);
     $type = PostCategory::fromString("foo");
 }
 private function givenANewPost(PostId $id)
 {
     return $this->scenario->withAggregateId($id)->given([new PostWritten($id, "Title", "Content", PostCategory::fromString(PostCategory::NEWSPOST))]);
 }