Nhóm và tính tổng trong mảng
Nhóm và tính tổng cho mảng (Group by and sum array)
$groups = $data->groupBy('employee');
$array = $groups->mapWithKeys(function ($group, $key) {
return [
$key =>
[
'employee' => $key,
'totalhours' => $group->sum('totalhours'),
]
];
});