Skip to content

N +1 on Select input with relationship when used within a repeater #18171

@GeorgeFourkas

Description

@GeorgeFourkas

Package

filament/filament

Package Version

4.1.6

Laravel Version

12.33

Livewire Version

3.6.4

PHP Version

8.3

Problem description

When adding a Select input with relationship() method (many to many) inside a repeater, instead of eager loading all the items' filament retrieves the relationships one by one. the result is n+1 problem. Below i am attaching a screenshot from the laravel debugbar in a simple filament form.

For the context, i have created a sample project using 3 models. Project, Task, and User.

I added a repeater within the project resource which has 2 fields. The task name, and the Select element which relates to the many to many task-user relationship.

Image

Expected behavior

It should eager load the many to many relationship between Task and User models.

Steps to reproduce

download the project. run composer install, copy .env.example to .env, run php artisan key:generate, run php artisan db:seed, run php artisan make:filament-user and enter the user credentials. open the /admin/projects user. click a project and open laravel debugbar panel.

Reproduction repository (issue will be closed if this is not valid)

https://github.com/GeorgeFourkas/filament_repeater_issue

Relevant log output

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    Status

    Todo

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions