F
Filament7mo 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
ModestasV7mo 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
ModestasV7mo ago
On the table, you can modify the query and add eager loading as needed
Prodex
ProdexOP7mo ago
perfect, that worked. Thank you!
Want results from more Discord servers?
Add your server