Sunday, March 11, 2018

Using min and max numbers against one value - development

Using min and max numbers against one value

I’m creating a property app in laravel. And I have a filtered search. The filtered search, searches all of the properties in the database. Each property has a column bedroom, with the number of bedrooms eg 4.

I wan’t a user in the search to specifiy the minimum, and the maximum bedrooms a property should have and return all poroperteies whose bedrooms fall in that range. For example if min = 2, and max = 5 all properties which have 2,3,4,5 bedrooms are shown, but nothing else. Here is my attempt, but i’m not sure where to go with it.

Bedroom fields for min and max

<div class="row mt-md-4">
              <div class="col-md-3">
                <select class ="form-control" id="min-bedrooms" name="min-bedrooms">
                  @foreach ($specs as $bedroom)
                    <option></option>
                  @endforeach
                </select>
              </div>
              <div class="col-md-3">
                  <select class ="form-control" id="max-bedrooms" name="max-bedrooms">
                    @foreach ($specs as $bedroom)
                      <option></option>
                    @endforeach
                  </select>
              </div>

Search controller

public function search(Request $request){
  $user = Auth::user();
  $properties = PropertyAdvert::where([
    ['county', '=', $request->input('county')],
    ['town', '=', $request->input('town')],
    ['min-bedrooms', '>=', $request->input('min-bedrooms')],
    ['max-bedrooms', '<=', $request->input('max-bedrooms')]
  ])->get();

  return view('pages/search/results', compact('properties', 'user'));
}

The filtered search works for county and towns but how do i get it for bedrooms



from Laravel Questions and Answers https://laravelquestions.com/laravel/using-min-and-max-numbers-against-one-value/
via Lzo Media

No comments:

Post a Comment