country = request()->route('country'); } public function with(): array { return [ 'courses' => Course::with(['lecturer', 'createdBy']) ->withExists([ 'courseEvents as has_future_events' => fn($query) => $query->where('from', '>=', now()) ]) ->when($this->search, fn($query) => $query ->where('name', 'ilike', '%'.$this->search.'%') ->orWhere('description', 'ilike', '%'.$this->search.'%'), ) ->orderByDesc('has_future_events') ->paginate(15), ]; } }; ?>