'Date added', 'rating' => 'Rating', 'title' => 'Title' ]; public const int PAGINATION = 30; public function updatedEntryId(): void { $this->resetPage(); $this->dispatch('filters-updated'); } public function updatedRating(): void { $this->resetPage(); $this->dispatch('filters-updated'); } public function clearFilters(): void { $this->reset([ 'entryId', 'rating' ]); $this->dispatch('filters-updated'); $this->resetPage(); } public function setSort(string $field): void { if( $this->sortBy === $field ) { $this->sortDir = $this->sortDir === 'asc' ? 'desc' : 'asc'; } else { $this->sortBy = $field; $this->sortDir = 'asc'; } $this->resetPage(); $this->dispatch('filters-updated'); } private function buildQuery() { $query = EntryReview::query()->with([ 'entry' ]); if( $this->entryId ) { $query->where('entry_id', $this->entryId); } if( $this->rating ){ $query->where('rating', $this->rating); } return $query->orderBy($this->sortBy, $this->sortDir); } public function render() { return view('livewire.reviews', [ 'reviews' => $this->buildQuery()->paginate(self::PAGINATION), ]); } }