I have search function where it searches into several model and get results back, now i would like to have all those model results into one variable so i can use only one variable in my blade.
How can i do that?
Code
public function results(Request $request) {
$q = $request->input('q');
$products = Product::where('name', 'like', "%{$q}%")
->orWhere('body', 'like', "%{$q}%")
->paginate(9);
$posts = Post::where('name', 'like', "%{$q}%")
->orWhere('body', 'like', "%{$q}%")
->paginate(9);
$pages = Page::where('name', 'like', "%{$q}%")
->orWhere('body', 'like', "%{$q}%")
->paginate(9);
$tags = Tag::where('name', 'like', "%{$q}%")
->paginate(9);
$jobs = Job::where('name', 'like', "%{$q}%")
->orWhere('body', 'like', "%{$q}%")
->paginate(9);
$categories = Category::where('name', 'like', "%{$q}%")
->orWhere('body', 'like', "%{$q}%")
->paginate(9);
$listings = Listing::where('name', 'like', "%{$q}%")
->orWhere('body', 'like', "%{$q}%")
->paginate(9);
$portfolios = Portfolio::where('name', 'like', "%{$q}%")
->orWhere('body', 'like', "%{$q}%")
->paginate(9);
$services = Service::where('name', 'like', "%{$q}%")
->orWhere('body', 'like', "%{$q}%")
->paginate(9);
return view('front.pages.search', compact('products', 'q', 'pages', 'posts', 'tags', 'jobs', 'categories', 'listings', 'portfolios', 'services'))->withQuery($q);
}