typeFilter = ''; $this->from = ''; $this->to = ''; $this->search = ''; $this->resetPage(); } public function updated(string $property): void { if (in_array($property, ['typeFilter', 'from', 'to', 'search'], true)) { $this->resetPage(); } } public function with(): array { $events = ActivityEvent::query() ->with('user') ->when($this->typeFilter !== '', fn ($query) => $query->where('type', $this->typeFilter)) ->when($this->from !== '', fn ($query) => $query->where('occurred_at', '>=', $this->from)) ->when($this->to !== '', fn ($query) => $query->where('occurred_at', '<=', $this->to)) ->when($this->search !== '', function ($query) { $query->where(function ($inner) { $inner->where('description', 'like', "%{$this->search}%") ->orWhere('actor_label', 'like', "%{$this->search}%"); }); }) ->orderByDesc('occurred_at') ->orderByDesc('id') ->paginate(50); return [ 'events' => $events, 'types' => ActivityType::cases(), ]; } }; ?>