Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Respect's avatar

why search stop working after i add attribute attributes to #[computed] property

  • without any attribute in computed is working
  • with pristst #[Computed(persist:true)] or #[Computed(cache:true)] search stoped working
  #[Computed()]
    public function transactions()
    {
        return Transaction::query()
            ->when((bool) $this->filters['status'], function ($query) {
                $query->where('status', $this->filters['status']);
            }
            ->search('title', $this->search)->orderBy($this->sortField, $this->sortDirection)->paginate(10);
    }

0 likes
7 replies
tykus's avatar

What does stop working mean; what error message (or change in expected behaviour) was observed?

1 like
Respect's avatar

@tykus when typing inside search input search working and data filtered if i use #[Computed()]

if i added attribute to cache the data like for better preformance like #[Computed(cache:true)] or #[Computed(persist:true)] - typing in search input not filter the data without any error

if i removd attribute cache or presists back to work 100% so problem in attributes

tykus's avatar
tykus
Best Answer
Level 104

@Respect okay, I understand. I believe the problem is what you are doing rather than how

If you are have cached the result of the query; why would you expect the resultset to change if you do not bust the cache? Let's say you persist with a very short TTL, e.g. 1 second; I suppose that will work, right?

#[Computed(persist: true, seconds: 1)]
public function transactions()
{
    // ...

But now you have to ask yourself, why would I cache the results for only one second, it makes no sense.

1 like
Respect's avatar

@tykus first thanks for answer - how to make this scenario - cache data & make search working with cached data untill i create or update new data will delete the cache using unset

so my question how to make search working with long live cache untill add new data and remove cache manully

tykus's avatar

@Respect but you're paginating the query result; so your cache will have only one page of Transactions. What use is there to search within just one page of data?

How slow is the database query that caching is the solution you want to reach for?

1 like
tykus's avatar

@Respect 100000 is not a lot of database records; I would try to optimise the query first; perhaps identifying and defining columns to index.

What is your search Builder method doing?

1 like

Please or to participate in this conversation.