传入对象的值然后搜索该对象

Passing in value of object then searching against that object

我有一个搜索功能可以找到其偏好与房东 属性 相匹配的用户。这样很好很好,但是我希望楼主能够select一个属性,然后按搜索,把那个属性对象传过去

这是搜索的图片

从列表中选择的 属性 将用于在搜索中进行搜索。

这是搜索的视图

<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 searchhome(){
      //Search Filter UI
      //Populates fields.
      $user = Auth::user();
      $properties = PropertyAdvert::where('user_id', Auth::id())->get();
      return view('pages/account/search/index', compact('user', 'properties'));}

接下来是逻辑

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'));
  }

我尝试使用请求对象将 selected 属性 设置为被比较对象。

有什么想法吗?

不是用地址填充 select 值,而是用 属性 的 ID 填充它,然后通过从 select.

$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();