public static function getCategoryFeed($slug = null)
 {
     $category = Category::whereRaw("LOWER(name) = '{$slug}'")->first();
     if ($category) {
         return Post::isPublished()->where('categories_id', '=', $category->id)->orderBy('published_at', 'desc');
     }
 }
 protected function loadPosts()
 {
     //\Log::info($this->parentPage);
     if ($this->parentPage != '') {
         $parent = $this->parentPage;
         $BlogPosts = BlogPost::where('parent', $parent);
     } else {
         $BlogPosts = new BlogPost();
     }
     $BlogPosts = $BlogPosts->isPublished();
     /*
      * Preset Fitlers
      * First we cycle through all possible preset filtering
      * @type - category,tag,author,date-time
      */
     if ($this->property('filter_type') == 'category') {
         $category_name = $this->property('filter_value');
         $category = CategoryModel::whereRaw("LOWER(name) = '{$category_name}'")->first();
         if ($category) {
             $catID = $category->id;
         } else {
             $catID = '#';
         }
         $BlogPosts->filterByCategory($catID);
     }
     if ($this->property('filter_type') == 'tag') {
         $tag = TagModel::where('name', '=', $this->property('filter_value'))->first();
         return $tag->posts()->paginate($this->property('postsPerPage'));
     }
     if ($this->property('filter_type') == 'author') {
         $author = BackendUserModel::findUserByLogin($this->property('filter_value'));
         if ($author) {
             $author_id = $author->id;
         } else {
             $author_id = '#';
         }
         $BlogPosts->filterByAuthor($author_id);
     }
     /*
      * Filter Request
      * Next we cycle through all possible request filters
      * @type - category,tag,author,canonical
      * (canonical requires additional different page vars /:year?/:month?/)
      */
     if ($this->param('filter')) {
         if ($this->param('filter') !== 'category' && !$this->param('slug')) {
             $slug = $this->param('filter');
             $type = 'category';
         } else {
             $type = $this->param('filter');
             $slug = $this->param('slug');
         }
         $slug = $slug;
         $slug = strtolower($slug);
         $slug = str_replace('-', ' ', $slug);
         $slug = str_replace('%20', ' ', $slug);
         if ($type == 'category') {
             $this->page['blogCurrentCategorySlug'] = $slug;
             $category = CategoryModel::whereRaw("LOWER(name) = '{$slug}'")->first();
             if ($category) {
                 $catID = $category->id;
             } else {
                 $catID = '#';
             }
             $BlogPosts->filterByCategory($catID);
         } elseif ($type == 'tag') {
             $this->page['blogCurrentTagSlug'] = $slug;
             $tag = TagModel::where('name', '=', $slug)->first();
             if ($tag) {
                 return $tag->posts()->paginate($this->property('postsPerPage'));
             }
             return false;
         } elseif ($type == 'author') {
             $author = BackendUserModel::findUserByLogin($slug);
             if ($author) {
                 $author_id = $author->id;
             } else {
                 $author_id = '#';
             }
             $BlogPosts->filterByAuthor($author_id);
         } elseif ($type == 'search') {
             $this->page['search_slug'] = $slug;
             $BlogPosts->filterBySearch($slug);
         } elseif ($type == 'cannonical') {
             $y = $this->param('year');
             $m = $this->param('month');
             $BlogPosts->filterByDate($y, $m);
         } else {
             $component = $this->addComponent('Radiantweb\\Problog\\Components\\Post', 'proBlogPost', array('slug' => $slug));
             $component->onRun();
             $this->render_post = $this->page['render_post'] = $slug;
             return $this->render_post;
         }
     }
     /*
      * no filters, we go get all
      */
     $posts = $BlogPosts->orderBy('published_at', 'desc')->paginate($this->property('postsPerPage'), $this->currentPage);
     //$queries = DB::getQueryLog();
     //$last_query = end($queries);
     //\Log::info($last_query);
     return $posts;
 }
 private static function getBlogCategoryRenderUrls($theme, $item, $allcat = false)
 {
     $page = CmsPage::loadCached($theme, $item->cmsPage);
     $result = [];
     $categories = Category::lists('slug', 'name');
     $pages = [];
     if ($item->nesting > 0) {
         foreach ($categories as $slug => $name) {
             if ($allcat) {
                 $url = CmsPage::url($page->getBaseFileName(), ['filter' => 'category', 'slug' => $slug], false);
                 $url = Str::lower($url) . '/';
                 $pages[] = array('title' => $name, 'url' => $url);
             } else {
                 $category = Category::whereRaw("LOWER(slug) = '{$slug}'")->first();
                 $categoryPages = Post::filterByCategory($category->id)->get();
                 $pageUrl = CmsPage::url($page->getBaseFileName(), ['slug' => $slug], false);
                 $pageUrl = str_replace('/default', '', Str::lower($pageUrl) . '/');
                 foreach ($categoryPages as $cpage) {
                     $pages[] = array('title' => $cpage->title, 'url' => Str::lower($pageUrl) . $cpage->slug . '/');
                 }
             }
         }
     }
     return $pages;
 }