country = request()->route('country', config('app.domain_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.'%'), ) ->whereHas('courseEvents.venue.city.country', fn($query) => $query->where('countries.code', $this->country)) ->orderByDesc('has_future_events') ->paginate(15), ]; } }; ?>