title: Laravel 5. Using the USING operator
body: <p>I tried to find it for a long time, and I can't believe that Laravel doesn't have this functionality.</p>
  
  <p>So, I can write:</p>
  
  <pre><code>select * from a join b where a.id = b.id
  </code></pre>
  
  <p>or more beautiful:</p>
  
  <pre><code>select * from a join b using(id)
  </code></pre>
  
  <p>First case is simple for Laravel:</p>
  
  <pre><code>$query-&gt;leftJoin('b', 'a.id', '=', 'b.id')
  </code></pre>
  
  <p>But how to write second case? I expect that it should be simple and short, like:</p>
  
  <pre><code>$query-&gt;joinUsing('b', 'id')
  </code></pre>
  
  <p>But thereis no such method and I can't find it.</p>
  
  <p>PS: it's possible that the answer is very simple, it's just hard to find by word "using", because it's everywhere.</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>I'm going deeper to source, trying to make scope or pass a function to join, but even inside of this function I can't to anything with this $query. Example:</p>
  
  <pre><code>public function scopeJoinUsing($query, $table, $field) {
      sql($query-&gt;join(\DB::raw("USING(`{$field}`)")));
      // return 
      // inner join `b` on USING(`id`)  ``
      // yes, with "on" and with empty quotes
      sql($query-&gt;addSelect(\DB::raw("USING(`{$field}`)")));
      // return 
      // inner join `b` USING(`id`) 
      // but in fields place, before "FROM", which is very logic :)
  }
  </code></pre>
  
  <p>So even if forget about scope , I can't do this in DB::raw() , so it's impossible... First time I see that something impossible in Laravel.</p>