Laravel 传入对象的值,然后对该对象进行搜索
我有一个搜索工作,可以找到用户的偏好匹配房东的财产。这一切都很好,但我希望房东能够选择一个财产,然后按搜索,并通过该财产对象进行比较 这是搜索的图像Laravel 传入对象的值,然后对该对象进行搜索,laravel,laravel-5,eloquent,request,query-builder,Laravel,Laravel 5,Eloquent,Request,Query Builder,我有一个搜索工作,可以找到用户的偏好匹配房东的财产。这一切都很好,但我希望房东能够选择一个财产,然后按搜索,并通过该财产对象进行比较 这是搜索的图像 <div class="row"> <div class="col-md-10"> <select class="form-control" id="property_address" name="property_address">
<div class="row">
<div class="col-md-10">
<select class="form-control" id="property_address" name="property_address">
<!--Gets all counties from DB -->
@foreach ($properties as $property)
<option value="{{$property->address . ', ' . $property->town . ', ' . $property->county}}">{{$property->address . ', ' . $property->town . ', ' . $property->county}}</option>
@endforeach
</select>
</div> <!-- ./ col-6-->
</div> <!-- ./ row-5 -->
<div class="row mt-md-4">
<div class="col-md-4">
<button type="submit" class="form-control btn btn-primary">
Search
</button>
</div>
</div>
从列表中选择的任何属性都将用于在搜索中对其进行搜索
这是搜索的视图
<div class="row">
<div class="col-md-10">
<select class="form-control" id="property_address" name="property_address">
<!--Gets all counties from DB -->
@foreach ($properties as $property)
<option value="{{$property->address . ', ' . $property->town . ', ' . $property->county}}">{{$property->address . ', ' . $property->town . ', ' . $property->county}}</option>
@endforeach
</select>
</div> <!-- ./ col-6-->
</div> <!-- ./ row-5 -->
<div class="row mt-md-4">
<div class="col-md-4">
<button type="submit" class="form-control btn btn-primary">
Search
</button>
</div>
</div>
其次是逻辑
public function searchresults(Request $request){
//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
//Attempting to get value of property by name
$property = $request->property_address;
$result = $pref
->where('county' , $property->county)
->where('type' , $property->type)
->where('rent', '<=', $property->rent)
->where('bedrooms', '<=', $property->bedrooms)
->where('bathrooms', '<=', $property->bathrooms);
$users = $result->get();
return view('pages/account/search/results', compact('users'));
}
公共函数搜索结果(请求$Request){
//获取作为租户的所有用户
$tenants=User::where('userType','tenant')->first();
//获取所有首选项
$preferences=TenantPreferance::all()->first();
//获取与租户id匹配的首选项
$pref=$Prefereances::where('user_id',$tenants->id)->first();
//获取当前登录用户属性
//正在尝试按名称获取属性的值
$property=$request->property\u地址;
$result=$pref
->其中('county',$property->county)
->其中('type',$property->type)
->其中('rent','不是用地址填充select值,而是用属性的ID填充它,然后用select传递的ID从数据库中获取该属性
$property = Property::find($request->property_id);
$result = $pref
->where('county' , $property->county)
->where('type' , $property->type)
->where('rent', '<=', $property->rent)
->where('bedrooms', '<=', $property->bedrooms)
->where('bathrooms', '<=', $property->bathrooms);
$users = $result->get();
$property=property::find($request->property\u id);
$result=$pref
->其中('county',$property->county)
->其中('type',$property->type)
->where('rent','您的帖子中是否缺少一些代码?如果$property
是表单中的输入,则它不会是具有该特定属性值的对象。