Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

FounderStartup's avatar

Correct query for multiplier filters ?

I need to show listings of projects with following filters :

  1. If locality of a city is selected
  2. Type of listings a. for sale b. for purchase c. for rent d. for rent out
  3. type of BHk a. 1 bhk b. 2-3 bhk c. 4 bhk onwards
  4. 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.

0 likes
4 replies
Tray2's avatar

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 . '%')
1 like
FounderStartup's avatar

@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.