user(); if (!$profile || !$user instanceof User) { return; } $locale = App::getLocale(); $published = function ($query) use ($locale) { $query->where('locale', $locale) ->whereDate('from', '<=', now()) ->where(fn ($q) => $q->whereDate('till', '>', now())->orWhereNull('till')); }; $polls = Poll::openNow() ->whereHas('post.translations', $published) ->with(['post.translations' => $published]) ->orderByRaw('closes_at IS NULL') ->orderBy('closes_at') ->orderByDesc('id') ->limit(20) ->get(); foreach ($polls as $poll) { if ($poll->isTargetedAt($profile, $user) && $poll->responseFor($profile, $user->id) === null) { $translation = $poll->post->translations->first(); $this->pollId = $poll->id; $this->title = $translation->title; $this->excerpt = $translation->excerpt; $this->slug = $translation->slug; $this->questionCount = $poll->questions()->count(); $this->hasContent = trim(strip_tags((string) $translation->content)) !== ''; return; } } } public function render() { return view('livewire.main-page.poll-card-full'); } }