title: Laravel query with "if" conditions?
body: <p>I'm trying to make an advanced search form with Laravel 4, and this is the query:</p>
  
  <pre><code>$result = DB::table('users_ads')
          -&gt;join('ads', 'users_ads.ad_id', '=', 'ads.id')         
          -&gt;orderBy($column, $method)
          -&gt;where('status', TRUE)
          -&gt;where(function($query) use ($input)
          {
              $query-&gt;where('short_description', $input['search'])
                      -&gt;where('category', $input['category'])
                      -&gt;where('product', $input['product']);
  
          })
          -&gt;join('users', 'users_ads.user_id', '=', 'users.id')
          -&gt;select('ads.id', 'ads.img1', 'ads.short_description', 'ads.category', 'ads.product', 'ads.price', 'users.city')
          -&gt;get();
  
      return $result;
  </code></pre>
  
  <p>The problem is that the user might not use all the input fields. So i want to include some if conditions in this part:</p>
  
  <pre><code>$query-&gt;where('short_description', $input['search'])
                      -&gt;where('category', $input['category'])
                      -&gt;where('product', $input['product']);
  </code></pre>
  
  <p>.. so if the input is empty, to remove the "where" condition.</p>