public function paginate($title, $category, $topics) { $query = Article::whereNotNull('published_at'); if (!empty($title)) { $query->where('title', 'LIKE', '%' . $title . '%'); } if (!empty($category)) { $query->whereHas('category', function ($q) use($category) { $q->where('categories.name', $category); }); } if (!empty($topics)) { foreach (explode(',', $topics) as $topic) { $query->whereHas('topics', function ($q) use($topic) { $q->where('topics.name', $topic); }); } } return $query->orderBy('id', 'DESC')->paginate(config('eruza.articles_per_page')); }
public function recentArticles() { return Article::whereNotNull('published_at')->orderBy('id', 'DESC')->take(3)->get(); }