/** @test */ public function a_post_can_be_written() { $id = PostId::generate(); $type = PostCategory::fromString(PostCategory::BLOGPOST); $this->scenario->when(function () use($id, $type) { return Post::createDraft($id, "Post Title", "Post Content", $type); })->then([new PostWritten($id, "Post Title", "Post Content", $type)]); }
/** * 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'); }