Correct query for multiplier filters ?
I need to show listings of projects with following filters :
- If locality of a city is selected
- Type of listings
a. for sale
b. for purchase
c. for rent
d. for rent out
- type of BHk
a. 1 bhk
b. 2-3 bhk
c. 4 bhk onwards
- posted by
a. individual
b. broker
My present controller query :
I am unable to write nested orWhere for the above filters :
$listings = Listings::with('user','project')
->whereHas('project', fn ($query)
=>$query->when($request->project_city, fn ($query, $city)
=> $query->where('project_city', $city))
->whereHas('city', fn ($query) => $query->where('status', 1)))
->latest()
->paginate(5)
->withQueryString();
What is the correct query.
I take it you pass those filters in your request.
Something like this should work.
Listing::where('city', 'like', '%' . $request->city . '%')
->where('type', 'like', '%' . $request->type . '%')
->where('posted_by'. 'like' , '%' . $request->posted_by . '%')
@Tray2 Thanks for your time.
I am using check boxes for filtering.
@Tray2 Kindly note that a user can click two type of BHKs. So how can we use as per your suggestion ?
Please or to participate in this conversation.