Repeater Duplicate queries when adding new item
My question is the following, why? when you add a new item to the repeater it executes the ->visible in all the previously added items, this causes the queries to be duplicated.
Forms\Components\Repeater::make('invoiceItems')
->relationship()
->schema([
Forms\Components\Group::make() //
->schema([
Select::make('categories'),
Select::make('article_id'),
Select::make('glass')
->visible(fn (Get $get): bool => Article::where('id', $get('article_id'))->where('is_kit', '!=', '0')->exists()),
Tnx !4 Replies
You’re not eager loading the relationships. There is a third callback parameter to the ->relationship() modifier to adjust the query.
Thanks for the answer, I didn't know the existence of eager loading, I looked at the Laravel documents but I don't understand how to apply it in this case, could you give me an example?, thx !
don't do sql query on every repeater item
maybe this video would help in your case https://www.youtube.com/watch?v=b_aYBTB4KCU&t=42s
Filament Daily
YouTube
Filament Tables: Avoid Duplicate SQL Queries
If you need to show a relationship value in the table, Filament can do it automatically, avoiding N+1 Query problem with Eager Loading.
More Filament examples on our website: https://filamentexamples.com