Eloquent query | Search in multiple tables
Hello guys,
I have question about multiple search query
I have in my Controller function:
public function search(Request $request)
{
$search = $request->get('search');
$results = DB::table('pages')->where('description', 'like', '%'.$search.'%')->where('visible',1)->paginate(6);
return view('pages.search', ['results' => $results]);
}
but I would like to search too in table 'subpages'. Can someone help me?
@ziben69 You just need to join another table and search on that.
This should be close to what you're looking for...
public function search(Request $request)
{
$search = $request->search;
$results = DB::table('pages')
->leftJoin('subpages', 'pages.subpage_id', '=', 'subpages.id')
->where('description', 'like', '%'.$search.'%')
->where('visible',1)
->paginate(6);
return view('pages.search', ['results' => $results]);
}
Think you are probably looking to do a union query. Not sure how you do that in eloquent. But should be easy enough to find out.
Please or to participate in this conversation.