@for ($d = 1; $d <= $daysInMonth; $d++) @php $date = \Carbon\Carbon::create($year, $month, $d); @endphp @endfor @php $grouped = collect($data)->groupBy('employee_id'); @endphp @foreach($grouped as $empId => $rows) @php $emp = $rows->first(); @endphp @php $total = 0; @endphp @for($d = 1; $d <= $daysInMonth; $d++) @php $date = sprintf('%04d-%02d-%02d', $year, $month, $d); $count = $rows ->firstWhere('attendance_date', $date) ->total_visit ?? 0; @endphp @endfor @endforeach