Пример #1
0
 public function getRelatedNewsByCategoryAndTags(Pages $page)
 {
     $category_ids = array_pluck($page->categories, 'id');
     $tag_ids = array_pluck($page->tags, 'id');
     if (count($category_ids) < 1) {
         $category_ids = [''];
     }
     if (count($tag_ids) < 1) {
         $tag_ids = [''];
     }
     $category_news = array_pluck(Categories::with('news.categories', 'news.tags')->whereIn('id', $category_ids)->get(), 'news');
     $tag_news = array_pluck(Tags::with('news.categories', 'news.tags')->whereIn('id', $tag_ids)->get(), 'news');
     if (count($category_news)) {
         $category_news = $category_news[0];
     }
     if (count($tag_news)) {
         $tag_news = $tag_news[0];
     }
     return array($category_news, $tag_news);
 }
Пример #2
0
 public function getBySlug($slug)
 {
     return Tags::with('news')->where('slug', $slug)->first();
 }