filters['startDate'] ?? null; $endDate = $this->filters['endDate'] ?? null; $data = News::query() ->when($startDate, fn ($q) => $q->whereDate('created_at', '>=', $startDate)) ->when($endDate, fn ($q) => $q->whereDate('created_at', '<=', $endDate)) ->orderByDesc('views') ->limit(10) ->get(); return [ 'datasets' => [ [ 'label' => 'Total Dilihat', 'data' => $data->pluck('views')->toArray(), 'backgroundColor' => '#EC4899', ], ], 'labels' => $data->pluck('title')->map(fn ($t) => str($t)->limit(30))->toArray(), ]; } protected function getType(): string { return 'bar'; } }