> */ public function __invoke(User $user, string $search, int $limit): array { $query = Event::query()->visibleTo($user)->where('is_published', true); GlobalSearch::whereTerms($query, ['title', 'description', 'location'], $search); return $query->orderByRaw('COALESCE(ends_at, starts_at) < ?', [now()])->orderBy('starts_at')->limit($limit)->get()->map(fn (Event $event) => [ 'title' => $event->title, 'url' => '/termine/'.$event->id, 'excerpt' => GlobalSearch::excerpt($event->description, $search), 'meta' => collect([ $event->all_day ? $event->starts_at->translatedFormat('j. F Y') : $event->starts_at->translatedFormat('j. F Y, H:i').' Uhr', $event->location, ])->filter()->implode(' · '), 'image' => $event->imageUrl('thumb'), ])->all(); } }