title: Laravel LeftJoin where
body: <p>I have some problems with my eloquent model, where I try to join two different tables in one</p>
  
  <p>Now I have two tables like.</p>
  
  <p>First tables name "company_saved_cv"</p>
  
  <pre><code>|id|company_id|worker_id |
  --------------------------
  |1|       2    |  61     |
  |3|       3    |  66     |
  |4|       2    |  69     |
  --------------------------
  </code></pre>
  
  <p>Second tables name "workers"</p>
  
  <pre><code>|id|location|name_and_surname|
  ------------------------------
  |61|London  | John John      |
  |62|London  | John John      |
  |66|London  | John John      |
  |67|London  | John John      |
  |68|London  | John john      |
  </code></pre>
  
  <p>And I whana get table like this.</p>
  
  <pre><code>|id|location|name_and_surname|worker_id|
  ---------------------------------------|
  |61|London  | John John      |  61     |
  |62|London  | John John      | NULL    |
  |66|London  | John John      | 66      |
  |67|London  | John John      | NULL    |
  |68|London  | John john      | NULL    |
  </code></pre>
  
  <p>where is my model function</p>
  
  <pre><code>public static  function CvSearch($interested_field, $location)
  {
  
      $match = "MATCH( `interested_fields`) AGAINST (?)";
  
      $query = Worker::select('workers.name_and_surname', 'workers.id', 'workers.location','company_saved_cv.worker_id')
          -&gt;leftJoin('company_saved_cv', function($leftJoin)
          {
              $leftJoin-&gt;on('company_saved_cv.worker_id', '=', 'workers.id')
                  -&gt;where('company_saved_cv.company_id', '=', Session::get('company_id') );
  
  
          })
          -&gt;where('workers.location', '=', $location)
          -&gt;whereRaw($match, array($interested_field))
          -&gt;orderBy('workers.created_at')
          -&gt;paginate(10);
      return $query;
  }
  </code></pre>
  
  <p>If I comment this line:<code>-&gt;where('company_saved_cv.company_id', '=', Session::get('company_id') );</code> It is working, but I need get only rows from workers table where company_id = 2 (in my example);</p>
  
  <pre><code>Session::get('company_id') = 2 
  </code></pre>
  
  <p>I will check it by logging it in laravel.log file.</p>
  
  <p>I fink it is problem with where('company_saved_cv.company_id', '=', Session::get('company_id') ); request, but I can't figure it out, maybe some one can help me?</p>