/** * @param $tag * * @return array */ public function postsByTag($tag) { $tag = Tag::where('tag', $tag)->firstOrFail(); $reverse_direction = (bool) $tag->reverse_direction; $posts = Post::where('published_at', '<=', Carbon::now())->whereHas('tags', function (Builder $q) use($tag) { $q->where('tag', '=', $tag->tag); })->where('is_draft', 0)->orderBy('published_at', $reverse_direction ? 'asc' : 'desc')->simplePaginate(config('easel.posts_per_page')); $posts->addQuery('tag', $tag->tag); return $this->assemblePostData($posts, $tag); }
/** * Display search result. * * @return \Illuminate\View\View */ public function index() { $params = request('search'); try { $posts = Post::search($params)->get(); $tags = Tag::search($params)->get(); } catch (\Exception $e) { //fallback to basic search $posts = Post::where('title', 'LIKE', '%' . $params . '%')->orWhere('subtitle', 'LIKE', '%' . $params . '%')->orWhere('content_raw', 'LIKE', '%' . $params . '%')->orWhere('meta_description', 'LIKE', '%' . $params . '%')->get(); $tags = Tag::where('tag', 'LIKE', '%' . $params . '%')->orWhere('title', 'LIKE', '%' . $params . '%')->orWhere('subtitle', 'LIKE', '%' . $params . '%')->orWhere('meta_description', 'LIKE', '%' . $params . '%')->get(); } return view('easel::backend.search.index', compact('params', 'posts', 'tags')); }