title: Laravel - Using joins with where across two tables
body: <p>I have table, 'jobs', indexed by job_id, and and table discussions with foreign key 'job_id'.</p>
  
  <p>In jobs I have a column called 'summary', and in discussions a column called 'body'. I want to search for the same text string in both of these columns across both these tables and return the applicable jobs.</p>
  
  <p>Eg, if a jobs record with job_id=7 has the string 'somestring' in it's 'summary' column, and a discussions record has foreign key job_id=20 and has string 'somestring', I want the job records for job_id=7 and job_id=20 returned.</p>
  
  <p>I am using laravel. I'm having trouble finding a solution, this is the closest I have got:</p>
  
  <pre><code>$query-&gt;join('discussions', function( $join ) use ( $search_term ){
                  $join-&gt;on('jobs.job_id', '=', 'discussions.job_id');
                  $join-&gt;where('discussions.body', 'LIKE', $search_term );                    
                  $join-&gt;orWhere('jobs.summary', 'LIKE', $search_term );                                  
              })
  </code></pre>
  
  <p>But this just returns everything from my discussions table. Does anyone have any suggestions?</p>
  
  <p>Thanks :)</p>