示例#1
0
 protected function loadCategory()
 {
     if (!($categoryId = $this->property('categoryFilter'))) {
         return null;
     }
     if (!($category = BlogCategory::whereSlug($categoryId)->first())) {
         return null;
     }
     return $category;
 }
示例#2
0
 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;
 }