country = request()->route('country'); } public function with(): array { return [ 'lecturers' => Lecturer::with([ 'createdBy', 'coursesEvents' => fn($query) => $query->where('from', '>=', now())->orderBy('from', 'asc') ]) ->withExists([ 'coursesEvents as has_future_events' => fn($query) => $query->where('from', '>=', now()) ]) ->withCount([ 'coursesEvents as future_events_count' => fn($query) => $query->where('from', '>=', now()) ]) ->when($this->search, fn($query) => $query ->where('name', 'ilike', '%'.$this->search.'%') ->orWhere('description', 'ilike', '%'.$this->search.'%') ->orWhere('subtitle', 'ilike', '%'.$this->search.'%'), ) ->orderByDesc('has_future_events') ->orderBy('name', 'asc') ->paginate(15), ]; } }; ?>