title: Laravel search query with multiple conditions
body: <p>Newbie to PHP/Laravel here so please be patient.</p>
  
  <p>I have a webpage that is searching based on 3 criteria for dogs , breed, sex and radius.</p>
  
  <p>here is the relevant code:</p>
  
  <p><strong>search page</strong></p>
  
  <pre><code>&lt;div class="col-md-12 zero-pad-left zero-pad-right"&gt; 
  {{ Form::open(array('action' =&gt; array('DogsController@index'), 'class'=&gt;'form width88', 'role'=&gt;'search', 'method' =&gt; 'GET')) }} 
  &lt;div id="prefetch"&gt;
    {{ Form::text('search-breed', null, array('class' =&gt; 'typeahead form-group form-control', 'placeholder' =&gt; 'Search by breed here...')) }}
    {{ Form::text('sex', null, array('class' =&gt; 'form-group form-control', 'placeholder' =&gt; 'Search by sex here...')) }}
    {{ Form::text('miles', null, array('class' =&gt; 'form-group form-control', 'placeholder' =&gt; 'Search by distance here...')) }}
  
  
  
  
  &lt;/div&gt;
  {{ Form::submit('Search', array('class' =&gt; 'btn btn-default search-bar-btn')) }}
  {{ Form::close() }} 
  </code></pre>
  
  <p></p>
  
  <p><strong>ControllerPage</strong></p>
  
  <pre><code>class DogsController extends \BaseController {
  
  public function __construct()
  {
      // call base controller constructor
      parent::__construct();
  
      // run auth filter before all methods on this controller except index and show
      $this-&gt;beforeFilter('auth', array('except' =&gt; array('show')));
  }
  
  /**
   * Display a listing of the resource.
   *
   * @return Response
   */
  public function index()
  {
      if (Input::has('search')) {
          $queryString = Input::get('search');
          $dogs = Dog::where('name', 'LIKE', "%$queryString%")-&gt;orderBy('name')-&gt;paginate(5);
      }
  
      elseif (Input::has('search-breed')) 
      {
          $dogs = Dog::whereHas('breed', function($q)     
          {
              $queryString = Input::get('search-breed');
              $q-&gt;where('name', 'LIKE', "%$queryString%");
  
          })-&gt;orderBy('name')-&gt;paginate(5);
  
      } //end elseif
  
      else {
          $dogs = Dog::orderBy('name')-&gt;paginate(5);
          } //end else
  
      return View::make('dogs.index')-&gt;with(array('dogs' =&gt; $dogs));
  } //end function index()
  </code></pre>
  
  <p>when i enter a search for poodle, male, within 20 miles, the url shows as follows:</p>
  
  <pre><code>http://ruff-love.dev/dogs?search-breed=poodle&amp;sex=M&amp;miles=20
  </code></pre>
  
  <p>The search currently works ok when searching for just breed.  </p>
  
  <p>I cant seem to figure out the syntax to add the SEX and RADIUS criteria also.
  it should allow for those criteria to be null and still perform the query.</p>
  
  <p>any advice would be greatly apprecaited</p>