How to eager load relationship inside infolist repeatable entry
I've enable prevent lazy loading like this in providers
Model::preventLazyLoading(! $this->app->isProduction());
I create a relationship manager and I display the data in infolist. but when it comes to repeatable entry like below example, I always got this error Attempted to lazy load [customer] on model [App\Models\Reply] but lazy loading is disabled.
I can put protected $with = ['customer'];
inside Model, but it's not a great solution IMO, so what should be the best way to eager load the relationshipSolution:Jump to solution
Yes, so helpful.. Now I use
->modifyQueryUsing()
and load relationship. it's working now, thanks20 Replies
Does this help?
https://www.answeroverflow.com/m/1110666450349326446
How to eager load in Relation Manager? - Filament
Hey guys, I am trying to optimise my app. So I used this:
Model::shouldBeStrict(app()->isLocal());
I found one problem in my RelationManager. I have User that has many Clients and he belongs to Address. When I want to edit User I got this error:
https://flareapp.io/share/dPbNO6LP#F129Solution
Yes, so helpful.. Now I use
->modifyQueryUsing()
and load relationship. it's working now, thanks@Vp Where did you put the
->modifyQueryUsing()
?
I get a method doesn't exist on the Infolist when I try it like this:
It only appears to work on $table
, but that has no effect on ths Infolist display when viewing the model...
Thanks for your help!I put in
$table
and I just use it inside infolist
Example:
Ok thanks for the example, but I still get the
but lazy loading is disabled
message for the relationship that I define in the modifyQueryUsing()
. Not sure what I am missing... But even debugging the modifyQueryUsing()
, and I'm not passing through it when on the Infolist...can you share some codes in which part it shows
lazy load disabled
?It's all
vendor
stuffThis is the code for the
table()
and infolist()
methods on the resourceMy relation is the
contactables
one and using the with('contact')
I am not sure but below part maybe the suspect, what is this
$record
contains? It looks like it's not load relationship. for me I just use normal ViewAction
ahh, is yours in a modal ?
wdym?
As in, is yours a simple resource? And when you click on view, it display the resource in a Modal, and not on it's own page?
Yes, only modal.. I use slideOver() as well 😆
If you use full page (own page) then I think you need to load realtionship on that page
Ok that might explain it, as I'm on a new page the relationship query isn't called from the
$table
...
Ok thanks I'll have a look there🆒
Thanks for your help!
Wc
For future visitors:
You can do something like this to eager load the relationship on the "View" page for your resource by overriding the
mount()
method, might be other ways or cleaner ways, but I couldn't see any other way to interact with the query:
Thanks Mark, your solution almost worked, but when I also have an Action button on the InfoList, it triggers the lazy loading error once again.
Turns out this is the way to do it:
And if you use an Action in the Infolist that also uses a relationship that should be eager loaded: