title: Laravel 3: Joining and getting sum of two tables, Is there a better way?
body: <p>I'm trying to get columns of a table while getting sum of another related table (I'm using a MySQL database). Tables are Advantages and Conversions, Advantages has a <code>conversionID</code> column to join. They are all related via models. I first tried to achieve this with Eloquent method, but I could not succeed, so I came up with this Fluent method, which is working fine:</p>
  
  <pre><code>DB::table('conversions')
      -&gt;join('advantages','advantages.conversionID','=','conversions.id')
      -&gt;where('conversions.used','=',0)
      -&gt;group_by('conversions.id')
      -&gt;get(array(
          'conversions.*',
          DB::raw('SUM(advantages.point) as totaladvantage')
        ))
  </code></pre>
  
  <p>I guess the query describes how the columns are and what I want to achieve.</p>
  
  <p>So my question is: Is there a more efficient way to achieve this? Using <code>DB::raw</code> for this seemed weird to me, and <code>sum()</code> method only returns sum of the columns. This is the almost only place where I wrote both fluent and raw query in my project, so that made me think if I'm missing something.</p>
  
  <p>Thanks in advance</p>