I have read the docs and I'm not clear on it. i followed search essentials and would like to use unions to search multiple columns. I have this right now in my post model:
public function scopeSearch($query, $search)
{
return $query->where('title', 'LIKE', "%$search%");
}
this is in my BlogController
public function index(Request $request)
{
$query = $request->get('q');
$posts = $query
? Post::search($query)->paginate(15)
: Post::paginate(15);
$tag = $request->get('tag');
$data = $this->dispatch(new BlogIndexData($tag));
$layout = $tag ? Tag::layout($tag) : 'blog.layouts.index';
return view($layout, $data)->withPosts($posts);
}
This is what I want to do but don't know to make it work
SELECT title FROM posts
WHERE title like "%$query%"
UNION
select subtitle from posts
WHERE subtitle like "%$query%"
union
select title from tags
WHERE title like "%$query%"
union
select subtitle from tags
WHERE subtitle like "%$query%"
any help would be beyond great
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community