/** @test */ public function retrieve_only_the_published_post() { factory('App\\Post')->create(['published' => '2015-01-01']); factory('App\\Post')->create(['published' => '2015-01-01']); $notPublished = factory('App\\Post')->create(['published' => '2030-12-31']); $this->assertCount(2, Post::PublishedPost()->get()); }
/** * Display a listing of the resource. * * @return \Illuminate\Http\Response */ public function index() { $posts = Post::PublishedPost()->get(); return view('post.index', compact('posts')); }