'from', 'type' => 'date', 'label' => 'Od', 'nullable' => true], ['key' => 'to', 'type' => 'date', 'label' => 'Do', 'nullable' => true], ]; } public function columns(): array { return [ ['key' => 'action_name', 'label' => 'Dejanje'], ['key' => 'decision_name', 'label' => 'Odločitev'], ['key' => 'activities_count', 'label' => 'Št. aktivnosti'], ]; } public function query(array $filters): Builder { return Activity::query() ->leftJoin('actions', 'activities.action_id', '=', 'actions.id') ->leftJoin('decisions', 'activities.decision_id', '=', 'decisions.id') ->when(! empty($filters['from']), fn ($q) => $q->whereDate('activities.created_at', '>=', $filters['from'])) ->when(! empty($filters['to']), fn ($q) => $q->whereDate('activities.created_at', '<=', $filters['to'])) ->groupBy('actions.name', 'decisions.name') ->selectRaw("COALESCE(actions.name, '—') as action_name, COALESCE(decisions.name, '—') as decision_name, COUNT(*) as activities_count"); } }