Business Model:
public function cat()
{
return $this->belongsToMany(BusinessCategory::class, 'cat_business', 'business_id' , 'cat_id');
}
BusinessCategory Model:
public function business()
{
return $this->belongsToMany(Business::class, 'cat_business','business_id', 'cat_id' );
}
Search Query:
public function search(Request $request){
// Get the search value from the request
$search = $request->input('search');
$catsearch = $request->input('category');
$location = $request->input('location');
// Search in the title and body columns from the posts table
$business = Business::query()
->where('name', 'LIKE', "%{$search}%")
->where('???', 'LIKE', "%{$catsearch}%")
->where('address', "%{$location}%")
->get();
dd($business);
// Return the search view with the resluts compacted
return view('frontend.search', compact('business'));
}