Data Structure
[
{
"id": "1",
"date": "2019-06-22",
"total": "1200" // THIS TOTAL IS A MUTATOR
},
{
"id": "2",
"date": "2019-06-24",
"total": "2200" // THIS TOTAL IS A MUTATOR
},
{
"id": "3",
"date": "2019-07-20",
"total": "2300" // THIS TOTAL IS A MUTATOR
},
]
What I am trying to do:
I want to group these data by MONTH and return the sum
Expected result:
2019-06
total is 1200
AND 2019-07
total is 4500
What I have tried:
$customer_branch = ExportInvoice::where('customer_branch_id', $customer_branch_id)
-> approved()
-> whereYear('date', $year)
-> orderBy('date', 'ASC')
-> get();
And I have tried to loop throw $customer_branch
and set data to array but I did not get the expected result