= 0; $i--) { $month = now()->subMonths($i); $labels[] = $month->format('M Y'); $data[] = (int) Vacation::query() ->where('status', ApprovalStatus::Approved) ->whereYear('start_date', $month->year) ->whereMonth('start_date', $month->month) ->sum('days'); } return [ 'datasets' => [ [ 'label' => 'Vacation Days', 'data' => $data, 'backgroundColor' => '#f59e0b', ], ], 'labels' => $labels, ]; } }