/** * Tes menambahkan Category */ public function testAdd() { $obj = new Category(); $obj->title = 'Title Unimportant'; $saved = $obj->save(); $this->assertTrue($saved); $obj_2 = Category::find($obj->id); if ($obj_2 !== null) { $this->assertEquals($obj, $obj_2); } // testing slug already exist $obj_3 = new Category(); $obj_3->title = 'Title Unimportant'; $saved = $obj_3->save(); $this->assertTrue($saved); $this->assertEquals('title-unimportant-new', $obj_3->slug); // testing slug already exist #2 $obj_3 = new Category(); $obj_3->title = 'Title Unimportant'; $saved = $obj_3->save(); $this->assertTrue($saved); $this->assertEquals('title-unimportant-new-new', $obj_3->slug); }
/** * Get posts of the category. * * @return Response */ public function getPosts($id) { $category = Category::find($id); if ($category) { $posts = $category->posts()->get(); return $posts; } throw new CrudException('category:getPosts'); }