如何修改已分组的laravel集合

时间:2015-06-23 22:20:31

标签: php laravel collections filter

我有以下代码,它接受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
}

0 个答案:

没有答案