F
Filament2mo ago
Harvey

Eager loaded relationship not updating after component action called

I have an action to upload a specific document, in v3 after it was called, my custom entry could use that newly created document via $model->documents but in v4 it does not update. It's like in v3 the whole model would be refreshed including eager loaded relations, but now the relations are cached. I don't want to call $model->documents()->get() because that's going to be a lot of extra database queries (I have quite a few fields), but I need the info to be fresh when an action is run to update the state of the field. I can confirm if I unset the relation it works. But what I would ideally want is for the whole claim to be fetched when the livewire request comes in and then I can use the eager loaded relation throught my infolist schema. Any ideas as to how I could combat this? TextEntry:
TextEntry::make("some_field")
->state(function (Model $model) {
return $model->documents->ofType($type)->count() > 3 ? 'foo' : 'bar';
}),
TextEntry::make("some_field")
->state(function (Model $model) {
return $model->documents->ofType($type)->count() > 3 ? 'foo' : 'bar';
}),
Solution:
Fixed by calling $model->refresh(); after my action is completed. I guess in v3 the caching was more lax, but in v4 it does not refresh the relations etc so you have to do that yourself.
Jump to solution
1 Reply
Solution
Harvey
Harvey2mo ago
Fixed by calling $model->refresh(); after my action is completed. I guess in v3 the caching was more lax, but in v4 it does not refresh the relations etc so you have to do that yourself.

Did you find this page helpful?