title: Problem with displaying individual filter in search form in Laravel
body: <p>I have search form to list properties/ads through certain criteria (property Bid-Ask, Property Payment, Property Type, price, quadrature`). When I select all the criteria that there are, it shows all and correct results in the table. The problem is when I select one or two criteria, it should return all properties that have just those two criteria, but instead I get redirected to 404 not found page. Also, my URL, then works fine, it shows the right URL, just with 404. I have three tables.</p>
  
  <pre><code>properties (id, city, price, quadrature, property_type)
  categories (id, category, priority)
  category_property (id, property_id, category_id)
  </code></pre>
  
  <p>Any help is greatly appreciated. Here is my code:</p>
  
  <p><strong>search.blade.php</strong></p>
  
  <pre><code>&lt;div class="col-md-8 order-md-1"&gt;
      &lt;div&gt;
          @if(isset($results))
          &lt;table class="table"&gt;
              &lt;thead&gt;
                  &lt;th&gt;Property Bid Ask&lt;/th&gt;
                  &lt;th&gt;Property Payment&lt;/th&gt;
                  &lt;th&gt;Property Type&lt;/th&gt;
                  &lt;th&gt;City&lt;/th&gt;
                  &lt;th&gt;Price&lt;/th&gt;
                  &lt;th&gt;Quadrature&lt;/th&gt;
              &lt;/thead&gt;
              &lt;tbody&gt;
                  @foreach ($results as $result)
                  &lt;tr&gt;
                      &lt;td&gt;{{ $result-&gt;category[0]-&gt;category }}&lt;/td&gt;
                      &lt;td&gt;{{ $result-&gt;category[1]-&gt;category }}&lt;/td&gt;
                      &lt;td&gt;{{ $result-&gt;category[2]-&gt;category }}&lt;/td&gt;
                      &lt;td&gt;{{ $result-&gt;city }}&lt;/td&gt;
                      &lt;td&gt;{{ $result-&gt;price }}&lt;/td&gt;
                      &lt;td&gt;{{ $result-&gt;quadrature }}&lt;/td&gt;
                  &lt;/tr&gt;
                  @endforeach
              &lt;/tbody&gt;
          &lt;/table&gt;
          @endif
  
      &lt;/div&gt;
      &lt;form id="searchForm" method="GET" action="/search"&gt;
          &lt;div class="row"&gt;
              &lt;div class="col-md-5 mb-3"&gt;
                  &lt;label&gt;City&lt;/label&gt;
                  &lt;input name="city" list="result" id="input" class="form-control"&gt;
                  &lt;datalist id="result"&gt;&lt;/datalist&gt;
              &lt;/div&gt;
          &lt;/div&gt;
          &lt;div class="row"&gt;
              &lt;div class="col-md-6 mb-6"&gt;
                  &lt;label&gt;Price&lt;/label&gt;
                  &lt;input type="number" name="min_price" class="form-control" placeholder="Min Price"&gt;
                  &lt;input type="number" name="max_price" class="form-control" placeholder="Max Price"&gt;
              &lt;/div&gt;
              &lt;div class="col-md-6 mb-6"&gt;
                  &lt;label&gt;Quadrature&lt;/label&gt;
                  &lt;input type="number" name="min_quadrature" class="form-control" placeholder="Min quadrature"&gt;
                  &lt;input type="number" name="max_quadrature" class="form-control" placeholder="Max quadrature"&gt;
              &lt;/div&gt;
          &lt;/div&gt;
          &lt;hr class="mb-4"&gt;
          &lt;div class="row"&gt;
  
              &lt;div class="col-md-4 mb-6"&gt;
                  &lt;h5&gt;Payment&lt;/h4&gt;
                  &lt;div class="d-block my-3"&gt;
                      &lt;div class="custom-control custom-radio"&gt;
                          &lt;input id="ponuda" name="propertyBidAsk" value="ponuda" type="radio" class="custom-control-input"&gt;
                          &lt;label class="custom-control-label" for="ponuda"&gt;Ponuda&lt;/label&gt;
                      &lt;/div&gt;
                      &lt;div class="custom-control custom-radio"&gt;
                          &lt;input id="potraznja" name="propertyBidAsk" value="potraznja" type="radio" class="custom-control-input"&gt;
                          &lt;label class="custom-control-label" for="potraznja"&gt;Potraznja&lt;/label&gt;
                      &lt;/div&gt;
                  &lt;/div&gt;
              &lt;/div&gt;
              &lt;div class="col-md-3 mb-6"&gt;
                  &lt;h5&gt;Property payment&lt;/h4&gt;
                  &lt;div class="d-block my-3"&gt;
                      &lt;div class="custom-control custom-radio"&gt;
                          &lt;input id="kupovina" name="propertyPayment" value="kupovina" type="radio" class="custom-control-input"&gt;
                          &lt;label class="custom-control-label" for="kupovina"&gt;Kupovina&lt;/label&gt;
                      &lt;/div&gt;
                      &lt;div class="custom-control custom-radio"&gt;
                          &lt;input id="izdavanje" name="propertyPayment" value="izdavanje" type="radio" class="custom-control-input"&gt;
                          &lt;label class="custom-control-label" for="izdavanje"&gt;Izdavanje&lt;/label&gt;
                      &lt;/div&gt;
                  &lt;/div&gt;
              &lt;/div&gt;
              &lt;div class="col-md-5 mb-6"&gt;
                  &lt;h5&gt;Property type&lt;/h4&gt;
                  &lt;div class="d-block my-3 "&gt;
                      &lt;div class="custom-control custom-radio"&gt;
                          &lt;input id="house" name="propertyType" value="house" type="radio" class="custom-control-input"&gt;
                          &lt;label class="custom-control-label" for="house"&gt;House&lt;/label&gt;
                      &lt;/div&gt;
                      &lt;div class="custom-control custom-radio"&gt;
                          &lt;input id="flat" name="propertyType" value="flat" type="radio" class="custom-control-input"&gt;
                          &lt;label class="custom-control-label" for="flat"&gt;Flat&lt;/label&gt;
                      &lt;/div&gt;
                  &lt;/div&gt;
              &lt;/div&gt;
          &lt;/div&gt;
          &lt;hr class="mb-4"&gt;
          &lt;button class="btn btn-primary btn-lg btn-block"&gt;Search&lt;/button&gt;
      &lt;/form&gt;
      &lt;script&gt;
          var onSubmitFunc = function(e){
              e.preventDefault();
              e.stopPropagation();
              if( e.stopImmediatePropagation ){
                  e.stopImmediatePropagation();
              }
              var propertyBidAsk = this["propertyBidAsk"].value.trim() || 0;
              var propertyPayment = this["propertyPayment"].value.trim() || 0;
              var propertyType = this["propertyType"].value.trim() || 0;
              var city = this['city'].value.trim() || 0;
              var min_price = this["min_price"].value.trim() || 0;
              var max_price = this["max_price"].value.trim() || 0;
              var price = min_price + "_" + max_price;
              var min_quadrature = this["min_quadrature"].value.trim() || 0;
              var max_quadrature = this["max_quadrature"].value.trim() || 0;
              var quadrature = min_quadrature + "_" + max_quadrature;
              url = propertyBidAsk.length === 0 ? '' : ( '/' + encodeURIComponent(propertyBidAsk) );
              url += propertyPayment.length === 0 ? '' : ( '/' +  encodeURIComponent(propertyPayment) );
              url += propertyType.length === 0 ? '' : ( '/' + encodeURIComponent(propertyType) );
              url += city.length === 0 ? '' : ( '/' + encodeURIComponent(city) );
              url += min_price.length === 0 ? '' : ( '/min_price' + "=" + encodeURIComponent(min_price) );
              url += max_price.length === 0 ? '' : ( '-max_price' + "=" + encodeURIComponent(max_price) );
              url += min_quadrature.length === 0 ? '' : ( '/min_quadrature' + "=" + encodeURIComponent(min_quadrature) );
              url += max_quadrature.length === 0 ? '' : ( '-max_quadrature' + "=" + encodeURIComponent(max_quadrature) );
              window.location.href = this.action + url;
          }
  
          document.addEventListener( 'DOMContentLoaded', function(){
              var srch = document.getElementById("searchForm");
              srch.addEventListener('submit', onSubmitFunc, false);
          }, false );
  
      &lt;/script&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p><strong>CategoryController.php</strong></p>
  
  <pre><code>&lt;?php
  
  namespace App\Http\Controllers;
  
  use App\Category;
  use App\Http\Controllers\Controller;
  use App\Property;
  use Illuminate\Http\Request;
  use Illuminate\Support\Facades\DB;
  use Illuminate\Support\Facades\Redirect;
  
  class CategoryController extends Controller
  {
      public function index()
      {
          $data = \DB::table('properties');
          return view('categories.search', compact('data'));
      }
  
      public function search($propertyBidAsk, $propertyType, $propertyPayment, $city, $price, $quadrature, Request $request, Property $property)
      {
  
          $category = $property-&gt;category;
  
          $property_obj = Property::query();
  
          if (!empty($request-&gt;city)) {
              $property_obj-&gt;where('city', 'LIKE', "%" . $request-&gt;city . "%");
          }
  
          if (!empty($request-&gt;min_price) &amp;&amp; !empty($request-&gt;max_price)) {
              $property_obj-&gt;whereBetween('price', [$min_price, $max_price]);
          }
  
          if (!empty($request-&gt;min_quadrature) &amp;&amp; !empty($request-&gt;max_quadrature)) {
              $property_obj-&gt;whereBetween('quadrature', [$min_quadrature, $max_quadrature]);
          }
  
          $results =  $property_obj-&gt;get();
          dd($request-&gt;all());
          return view('categories.search', compact('category', 'results'));
      }
  }
  </code></pre>
  
  <p><strong>web.php</strong></p>
  
  <pre><code>Route::get('/search', 'CategoryController@index');
  Route::get('/search/{propertyBidAsk}/{propertyPayment}/{propertyType}/
  {city}/{price}/{quadrature}', 'CategoryController@search');
  </code></pre>