How can I show transaction details bar chart? How can i show total transaction group by month in chart js?
I have a code where i can show total no of transactions in month. But I need total sum of transactions. Below is the code:
$pie_data = order::select('total_amount' ,'created_at')->get()->groupBy(function($pie_data){
return Carbon::parse($pie_data->created_at)->format('M');
});
$piemonths = [];
$piemonthTrans= [];
foreach($pie_data as $piemonth => $values){
$piemonths[] = $piemonth;
$piemonthTrans[] = count($values);
}
When i change count function with sum , it is showing error - "Call to undefined function App\Http\Controllers\Admin\sum()"
so, bear in mind that you are only grouping by month so next year and this years data will be lumped together. You need to ground by month and year
You are also loading every order into memory
Loop values, adding to total or convert to collection and use ->sum('total_anount')
better, use aggregate functions in the database
Please sign in or create an account to participate in this conversation.