startOfDay()->subDays(13); for ($i = 0; $i < 14; $i++) { $labels[] = $start->copy()->addDays($i)->format('Y-m-d'); } // SQLite-friendly group by date $rows = DB::table('photos') ->selectRaw("strftime('%Y-%m-%d', created_at) as d, count(*) as c") ->where('created_at', '>=', $start) ->groupBy('d') ->orderBy('d') ->get(); $map = collect($rows)->keyBy('d'); $data = array_map(fn ($d) => (int) ($map[$d]->c ?? 0), $labels); return [ 'labels' => $labels, 'datasets' => [ [ 'label' => __('admin.common.uploads'), 'data' => $data, 'borderColor' => '#f59e0b', 'backgroundColor' => 'rgba(245, 158, 11, 0.2)', 'tension' => 0.3, ], ], ]; } protected function getType(): string { return 'line'; } public function getHeading(): string|\Illuminate\Contracts\Support\Htmlable|null { return __('admin.widgets.uploads_per_day.heading'); } }