title: Conditional join in Laravel Fluent
body: <p>In Laravel PHP framework you can use a condition inside a where clause, like this (Fluent):
      </p>
  
  <pre class="lang-php prettyprint-override"><code>...
  -&gt;where(function($query) use ($var) {
      if(isset($var)) {
          $query-&gt;where('something', '=', $var);
      }
  })
  -&gt;...
  </code></pre>
  
  <p>So if you do not have a $var variable, the where clause will not be added to the query.</p>
  
  <p>I would like to do the same thing, but with a join clause, so for example join with another table only if $var is set, but this does not work, the query collapses:</p>
  
  <pre class="lang-php prettyprint-override"><code>...
  -&gt;join('tableB', function($query) use ($var) {
      if(isset($var)) {
          $query-&gt;on('tableA.id', '=', 'tableB.id'); 
      }
  })
  -&gt;...
  </code></pre>
  
  <p>Any suggestion?</p>