subMonths(1)->format('%B'); // محاسبه مجموع کارکرد برای هر کارمند به تفکیک ماه $employeeTotals = []; foreach ($data as $employee) { // تبدیل آبجکت به آرایه در صورت نیاز برای حلقه $recordsGrouped = is_array($employee->records) ? $employee->records : (array)$employee->records; $monthlyTotals = []; foreach ($recordsGrouped as $month => $attendances) { $tsec = 0; foreach ($attendances as $attendance) { // اگر duration موجود باشه استفاده می‌کنیم if (!empty($attendance->duration)) { [$h, $m, $s] = explode(':', $attendance->duration); $tsec += (int)$h * 3600 + (int)$m * 60 + (int)$s; } } $hours = floor($tsec / 3600); $minutes = floor(($tsec % 3600) / 60); // ذخیره زمان برای این ماه $monthlyTotals[$month] = sprintf('%02d:%02d', $hours, $minutes); } // ذخیره کل ماه‌ها برای این کارمند $employeeTotals[$employee->id] = $monthlyTotals; } ?> @extends('app') @section('content')
@if(empty($data) || count($data) == 0)

اطلاعاتی موجود نمیباشد

@else
@foreach($data as $employee) @endforeach
@foreach($data as $employee) @endforeach @endif
@endsection