我有一个迷你搜索功能。我试图让房东找到其房产偏好等于或大于房产的房客。
所以,如果房东在都柏林拥有3个床位,2个浴室。
搜索将返回所有指定他们想要拥有3张床或更少床位,2个或更少浴室的房客。
我遇到的问题是只有县匹配。
这些是当租户指定他们想要都柏林房产并且房东在都柏林拥有房产时所匹配的记录。
签署房东的财产记录 Property Record
租户优先记录 Property Record
这是代码
public function searchresults(){
//Gets all users that are tenants
$tenants = User::where('userType', 'tenant')->first();
//Gets all preferances
$Prefereances = TenantPreferance::all()->first();
//Gets the prefereances that match a tenant id
$pref = $Prefereances::where('user_id', $tenants->id)->first();
//Gets the current signed in users property
$property = PropertyAdvert::where('user_id', Auth::user()->id)->first();
$result = $pref::where(
'county' , $property->county,
'type' , $property->type,
'rent', '<=', $property->rent,
'bedrooms', '>=', $property->bedrooms,
'bathrooms', '>-', $property->bathrooms
);
$users = $result->get();
return view('pages/account/search/results', compact('users'));
}
答案 0 :(得分:0)
只有县匹配,因为每个where()调用只应用于一个字段。试试这个:
$result = $pref::where('county' , $property->county)
->where('type', $property->type)
->where('rent', '<=', $property->rent),
->where('bedrooms', '>=', $property->bedrooms),
->where('bathrooms', '>=', $property->bathrooms);