title: Laravel: When doing an LEFT JOIN how to make alias of fields so I can access fields with the same name
body: <p>I have a "master" table, lets say is something like:</p>
  
  <pre><code>id       autoincrement
  name     varchar(10)
  category integer
  </code></pre>
  
  <p>Then I have a "detail" table, lets say:</p>
  
  <pre><code>id        autoincrement
  master_id integer
  qty       integer
  </code></pre>
  
  <p>I want to make a LEFT JOIN like:</p>
  
  <pre><code>SELECT * FROM master
  LEFT JOIN detail ON master.id = detail.master_id
  WHERE category=1
  </code></pre>
  
  <p>This query produces exactly what I want in SQL: A table with all the master records even if they don't have detail, in that case will get me the detail columns with NULL which is correct.</p>
  
  <p>Now in Laravel, I want to do something like:</p>
  
  <pre><code>$records = Master::where('category', '=', 1)
               -&gt;leftJoin('detail', 'master.id', '=', 'detail.master_id')
  </code></pre>
  
  <p>If the detail table is empty, it returns id as NULL </p>
  
  <p>I think this is because it returns <code>id</code> twice, first the <code>master.id</code>, and then the second <code>id</code> which comes from the detail table, is, of course, NULL</p>
  
  <p>So how can I alias the first (or second id) in order to access it?</p>