title: Laravel5.1 how to do a multi-condition query with if clause
body: <p>I am a beginner, and currently creating a laravel project which needs multi-condition query like this:</p>
  
  <p><strong>View layer sample</strong></p>
  
  <p><a href="https://i.stack.imgur.com/SPmkG.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/SPmkG.png" alt="enter image description here"></a></p>
  
  <p>Each of these three conditions could be blank.</p>
  
  <p>If one is blank, the corresponding controller should not add 'where clause' when querying the db.</p>
  
  <p>I know in java, I can apply if clause to this like:</p>
  
  <pre><code>String sql = "select field from table where 1 = 1";
  
  if(a!=null&amp;&amp;!a.isEmpty())
    sql+=" and a = '"+a+"'";
  
  then execute sql......
  </code></pre>
  
  <p>But in laravel, how do i address this? </p>