title: Eloquent advanced where within an advanced join
body: <p>I'm trying to do the following join:</p>
  
  <pre><code>Schedules::select()
       -&gt;leftJoin('histories', function ($j)
          {
              $j-&gt;on('histories.schedule_id', '=', 'schedules.id')
                  -&gt;where('histories.test', '=', DB::raw('schedules.test'))
                  -&gt;where(function ($q)
                  {
                      $q-&gt;where('histories.order_id', '=', 'schedules.order_id')
                          -&gt;orWhere('histories.customer_id', '=', DB::raw('schedules.customer_id'));
                  });
          });
  </code></pre>
  
  <p>When I do, Laravel reports the error:</p>
  
  <pre><code>Missing argument 2 for Illuminate\Database\Query\JoinClause::where()
  </code></pre>
  
  <p>How do I structure this query in Eloquent syntax so that I get the equivalent of the following for the join statement?</p>
  
  <pre><code>left join histories
      on histories.schedule_id = schedules.id
          and histories.test = schedules.test
          and (
              histories.order_id = schedules.order_id
              or histories.customer_id = schedules.customer_id
          )
  </code></pre>