protected function loadCategory() { if (!($categoryId = $this->property('categoryFilter'))) { return null; } if (!($category = BlogCategory::whereSlug($categoryId)->first())) { return null; } return $category; }
public function onGetByCategory() { if (Request::has('category')) { $category = Request::input('category'); } else { return; } if (Request::has('numberOfPost')) { $numberOfPost = Request::input('numberOfPost'); } else { $numberOfPost = 4; } $posts = Category::whereSlug($category)->first()->posts()->isPublished()->with('categories', 'tags')->orderBy('published_at', 'desc')->take($numberOfPost)->get(); /* * Add a "url" helper attribute for linking to each post and category */ $posts->each(function ($post) { $post->setUrl($this->property('postPage'), $this->controller); $post->categories->each(function ($category) { $category->setUrl($this->property('categoryPage'), $this->controller); }); }); return $posts; }