Hello, I'm consuming an API that returns a JSON which I transformed in the below collection:
Collection {#968
#items: array:2 [
0 => {#959
+"IdBoleto": 17406
+"DueDate": "2019-01-11T00:00:00"
+"PaymentDate": "2019-01-11T18:44:57.937"
+"CreditDate": null
+"PrincipalValue": 4.5
+"InterestValue": 0.0
+"FineValue": 0.0
+"TotalValue": 4.5
+"PaidValue": 4.5
+"Status": 5
+"MailToSend": "[email protected]"
+"PhoneToSend": null
+"Comments": "Webhook Teste"
+"OurNumber": "000000002654"
+"Identifier": "5"
+"ReturnMessage": null
+"ReturnCode": null
+"Barcode": null
+"DigitableLine": null
+"OccurrenceMotive": array:1 [
0 => {#960
+"OccurrenceCode": "06"
+"OccurrenceMessage": "PAYED"
+"Motives": array:1 [
0 => null
]
}
]
+"CustomerName": "Customer Name"
+"CustomerTaxNumber": "Tax Number"
+"PayerBankCode": null
+"PayerBankBranchCode": null
}
1 => {#961
+"IdBoleto": 17614
+"DueDate": "2019-01-28T00:00:00"
+"PaymentDate": "2019-01-25T13:34:31.307"
+"CreditDate": null
+"PrincipalValue": 4.3
+"InterestValue": 0.0
+"FineValue": 0.0
+"TotalValue": 4.3
+"PaidValue": 4.3
+"Status": 5
+"MailToSend": "[email protected]"
+"PhoneToSend": null
+"Comments": null
+"OurNumber": "000000002851"
+"Identifier": "Teste06"
+"ReturnMessage": null
+"ReturnCode": null
+"Barcode": null
+"DigitableLine": null
+"OccurrenceMotive": array:1 [
0 => {#962
+"OccurrenceCode": "06"
+"OccurrenceMessage": "PAYED"
+"Motives": array:1 [
0 => null
]
}
]
+"CustomerName": "Customer Name"
+"CustomerTaxNumber": "Tax Number"
+"PayerBankCode": null
+"PayerBankBranchCode": null
}
]
}
I tried to manipulate and group the collection information, but it didn't work.
$payed->groupBy(function ($item){
return Carbon::parse($item->DueDate)->format('Y-m');
});
I'm trying to group the data to have the information formatted as:
[
{
"quantity": 2,
"week": 36,
"totalValue": 8.9
},
{
"quantity": 2,
"week": 37,
"totalValue": 10
}
]
Could someone help me?