I have to write a query like : SELECT azon, SUM(points) points FROM stats GROUP BY azon;
Also I need to paginate them in Laravel3.
So I tried Stats::group_by('azon')->sum('points')->paginate(20);
. Of course this did not work. So I tried
$stats2 = DB::table('stats')
->select('azon', DB::raw('SUM(points) as points'))
->group_by('azon')
->paginate(20);
No results.
The last thing I tried was DB::query('SELECT azon, SUM(points) points FROM test_stats GROUP BY azon')
but this returns an array and I cannot paginate an array.
Any ideas, workarounds. I hope Laravel3 has something for this as this is a basic query.
The issue with your query is, select function in Query Builder accepts array parameter.
$stats2 = DB::table('stats')
->select( array( 'azon', DB::raw('SUM(points) as points') ) )
->group_by('azon')
->paginate(20);