我有以下代码,它接受CallRecords的集合,然后应用groupBy以及过滤器:
$Groups = $CallRecords->filter( function($CallRecord)
{
return isset($CallRecord->meta->reason_not_connected) && true;
})
->groupBy('meta.reason_not_connected');
return $Groups;
返回
"example": {
"Reached Voicemail - No Message": [
{
"id": "44",
"phone_number_id": "51",
},
{
"id": "55",
"phone_number_id": "31",
},
],
"Reached Voicemail - Left Message": [
{
"id": "19",
"phone_number_id": "11",
},
{
"id": "20",
"phone_number_id": "21",
},
]
}
如何将此集合变形以显示如下计数:
"example": {
"Reached Voicemail - No Message": 2,
"Reached Voicemail - Left Message": 2
}