I am developing a real estate site. I need to filter listings depending on the value of a radio button. How to handle this in my query ? The users have roles "broker" and "individual". I need to search listings depending on the roles of then user ( who has listed ).
My blade for radio button :
<div class="privacy-content">
<div class="media">
<div class="media-body">
<p class="font-roboto">Listings By All</p>
</div>
<label class="switch">
<input type="radio" name="radio1" value="all" checked=""><span class="switch-state"></span>
</label>
</div>
<div class="media">
<div class="media-body">
<p class="font-roboto">Listings By Brokers</p>
</div>
<label class="switch">
<input type="radio" name="radio1" value="broker" ><span class="switch-state"></span>
</label>
</div>
<div class="media">
<div class="media-body">
<p class="font-roboto">Listings By Individuals</p>
</div>
<label class="switch">
<input type="radio" name="radio1" value="individual"><span class="switch-state"></span>
</label>
</div>
</div>
My controller is :
$listingsforsale = Listings::with('listingtypename','project.builder','user','project','project.city','project.locality')
->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)))
->where ('status', '1')
->where('dealstatus',1)
->where('project_id', '<>', NULL)
->where('expiry_date','>' , now())
->where('listingtype', 1)
->when($request->bedrooms, function ($query) use ($request) {$query->whereIn('bhk', [$request->bedrooms ]);})
->when($request->project_locality, function ($query) use ($request) {$query->whereHas('project.locality', fn($query)=>$query->where('project_locality', $request->project_locality));})
->orderBy('featured', 'DESC')
->withCount('response')
->orderBy('response_count', 'DESC')
->paginate(10)
->withQueryString();