@foreach($users as $user)
@php
$currentMonth = now()->month;
$currentYear = now()->year;
$monthlyAttendances = $user->attendances->filter(function($attendance) use ($currentMonth, $currentYear) {
return \Carbon\Carbon::parse($attendance->date)->month == $currentMonth &&
\Carbon\Carbon::parse($attendance->date)->year == $currentYear;
});
$stats = [
'total' => $monthlyAttendances->count(),
'present' => $monthlyAttendances->where('status', 'present')->count(),
'late' => $monthlyAttendances->where('status', 'late')->count(),
'absent' => $monthlyAttendances->where('status', 'absent')->count(),
];
@endphp
{{ $stats['total'] }}
Total
{{ $stats['present'] }}
Hadir
{{ $stats['late'] }}
Terlambat
{{ $stats['absent'] }}
Tidak Hadir
@endforeach