/** * @param $id * @param $numberOfPosts * @return \Journal\Post */ public function getPosts($id, $numberOfPosts) { return Post::with(['author', 'tags'])->whereHas('tags', function ($query) use($id) { // set a query to fetch posts according to the tag ID to which // a tag is related to $query->where('id', '=', $id); })->where('active', '=', 1)->where('status', '=', 1)->orderBy('published_at', 'DESC')->paginate($numberOfPosts); }
/** * @param $authorId * @param $numberOfPosts * @return \Journal\Post */ public function getPostsByAuthor($authorId, $numberOfPosts) { return Post::with(['author', 'tags'])->where('author_id', '=', $authorId)->where('active', '=', 1)->where('status', '=', 1)->orderBy('published_at', 'DESC')->paginate($numberOfPosts); }