Laravel eloquent query to return sum of month orders

I have so far came up with this query:

Order::select(DB::raw('sum(price) as sums'), 
              DB::raw("DATE_FORMAT(created_at,'%e') as day")                                             
             ->where('seller_id', Auth::user()->id)
             ->whereBetween('created_at', [Carbon::now()->startOfMonth()
             ->orderBy('created_at', 'asc')

This returns an array like this:


This is almost what I need. I would now like to include even the name of the month in these results, like this:

[{"June" : {{"sums":145867,"day":"3"},{"sums":19567,"day":"28"}}}]  

Read more here:

Content Attribution

This content was originally published by m33ts4k0z at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: