F
Filament2mo ago
Prodex

How can I avoid N+1 problem in custom views?

As described in the docs I use a custom view for a table column and I'm using $getRecord() to access the eloquent model. This however makes an N+1 problem, because for every record displayed in the table the $getRecord() method retrieves the data from the database again. How can I avoid this? Thank you!
Solution:
Hi, this should help you: ```php return $table...
Jump to solution
3 Replies
Solution
ModestasV
ModestasV2mo ago
Hi, this should help you:
return $table
->modifyQueryUsing(function ($query) {
return $query->with('relationship');
})
return $table
->modifyQueryUsing(function ($query) {
return $query->with('relationship');
})
ModestasV
ModestasV2mo ago
On the table, you can modify the query and add eager loading as needed
Prodex
Prodex2mo ago
perfect, that worked. Thank you!
Want results from more Discord servers?
Add your server
More Posts