$bookings = Salon::find(3)->bookings;
$bookings->groupBy(['booking_status', function ($item) {
return \Carbon\Carbon::parse($item['created_at'])->format('Y-m');
}])->toArray();
이것은 나를 아래에 제공합니다.
"confirmed" => [
"2020-12" => [
[],[],[],[]
]
];
그러나 다음과 같은 것을 찾고 있습니다.
"confirmed" => [
"2020-12" => 4
];
두 가지 수준의 그룹화가 있고 두 번째 수준에서 항목을 계산하려면 다음을 수행 할 수 있습니다.
$bookings = Salon::find(3)->bookings;
$bookings->groupBy(['booking_status', function ($item) {
return \Carbon\Carbon::parse($item['created_at'])->format('Y-m');
}])->map(function ($dateGroup) {
return $dateGroup->map->count();
})->toArray();
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다