Filament v4 ->state uses cached values?
I upgraded from Filament v3 and noticed some behaviour.
So i have this piece of Code. We were using
->getStateUsing in v3 but ->state ist in de API doc so we changed it. Under the hood it is the same so it doesnt matter anyways.
The Field in make does not exist - so name does not exists on the Record. It always has beed calculated on the fly
Behaviour in v3: Every Row has the correct name
Behaviour in v4: Every Row has the same name
Also i added a dump and noticed it is only executed in the first row - so I think the value is chached somehow. Could't find anything in the docs https://filamentphp.com/docs/4.x/tables/columns/overview#setting-the-state-of-a-column
I also tried ->formatStateUsing but this method is not executed if the value of make - so the property - does not exist.
I'm missing something but kinda stuck right now. Using Filament v4.1.10
5 Replies
Well it seems
formatStateUsing is working if default(1) isset. So maybe this is the way to go for such calcuated field for which the field name does not exists.I am guessing you use name to collate first and last name correct? So the better way here would be to add a SQL Virtual Column with a custom migration, seE: https://laraveldaily.com/post/virtual-db-columns-laravel-migrations-mysql for performance and ease of use.
I suspect something is a miss for it to only work with default state. Can you report a bug with a reproduction repo?
Laravel Daily
Virtual DB Columns in Laravel Migrations and MySQL
Well this is a simplified example - we have used the
getStateUsing quite much -> Cannot make a virtual Column for everything 😄
As for now i haven't found a practiable solution. I don't think this is a bug - more like a different behaviour because of the new caching in V4. Different behaviour -> might have to change something in our code.If you find a solution for this let me know, as I have a similar problem with this too
Will do - unfortunately nothing worked yet
@Dan Harrin any idea on this? or a hint where to look?
Update: No smart solution found yet (._. )