Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

strongs's avatar

Filament infoList RepeatableEntry with array

I've been on this for 2 days solid but still can't seem to find a solution. I'm a newbie with Filament and Laravel so still finding my way around.

In my app I have two models that connect to a pivot table:

Users Model contains:

public function userEvents(): BelongsToMany
    {
        return $this->belongsToMany(Event::class, 'event_user', 'event_id', 'user_id')->withTimestamps()->using(EventUser::class);
    }

And the Event model contains:

public function eventUser(): BelongsToMany
    {
        return $this->belongsToMany(User::class, 'event_user', 'event_id', 'user_id')->withTimestamps()->using(EventUser::class);
    }

In my Filament EventResource, I have an infoList that contains this snippet:

InfoListSection::make('Attendees')
                        ->grow(false)
                        ->schema([
                            Split::make([
                                RepeatableEntry::make('Who is attending')
                                    ->state(function (Event $event) {
                                        $id = $event->getKey();
                                        $events = $event->eventUser()->where('event_id', $id)->get();
                                        $attendees = $events->map(function ($user) {
                                            return [
                                                'id' => $user->id,
                                                'name' => $user->name,
                                                'created_at' => $user->created_at->format('Y-m-d H:i:s'), 
                                            ];
                                        })->toArray();

                                        return $attendees;
                                        //dd($attendees[0]['name']);
                                    })

                                ->schema([
                                    TextEntry::make('attendees')
                                ])
                                ->contained(false)

                            ])


                        ]),
                ])->columnSpanFull()->from('md')

In the RepeatableEntry component, I'm trying to return a list of the users loaded onto current record. The array is returning the correct number of users with the correct data.

What I can't get my head around is how to display the users in the TextEntry of the RepeatableEntry component. This is what I get in the array:

array:5 [▼ // app/Filament/Resources/EventResource.php:383
  0 => array:3 [▼
    "id" => 1
    "name" => "Paul Armstrong"
    "created_at" => "2024-03-21 17:47:36"
  ]
  1 => array:3 [▼
    "id" => 17
    "name" => "Dr. Leopoldo Kerluke V"
    "created_at" => "2024-03-21 17:47:36"
  ]
  2 => array:3 [▼
    "id" => 24
    "name" => "Adriel Conn"
    "created_at" => "2024-03-21 17:47:36"
  ]
  3 => array:3 [▼
    "id" => 38
    "name" => "Lacey Morar"
    "created_at" => "2024-03-21 17:47:36"
  ]
  4 => array:3 [▼
    "id" => 45
    "name" => "Brigitte Will"
    "created_at" => "2024-03-21 17:47:36"
  ]
]

And this is what is returned in the TextEntry:

Attendees
Who is attending
Attendees
Attendees
Attendees
Attendees
Attendees

Grateful for any assistance.

0 likes
3 replies
LaryAI's avatar
Level 58

It seems like you're trying to display a list of attendees within the RepeatableEntry component in Filament. The issue you're facing is that the TextEntry component is not being populated with the actual attendee names.

To fix this, you need to ensure that the schema for the RepeatableEntry component is correctly set up to display the data for each attendee. You should use the statePath property to bind each TextEntry to the corresponding field in the attendee data.

Here's how you can modify your RepeatableEntry to display the attendee names:

InfoListSection::make('Attendees')
    ->grow(false)
    ->schema([
        Split::make([
            RepeatableEntry::make('Who is attending')
                ->state(function (Event $event) {
                    $id = $event->getKey();
                    $events = $event->eventUser()->where('event_id', $id)->get();
                    $attendees = $events->map(function ($user) {
                        return [
                            'id' => $user->id,
                            'name' => $user->name,
                            'created_at' => $user->created_at->format('Y-m-d H:i:s'), 
                        ];
                    })->toArray();

                    return $attendees;
                })
                ->schema([
                    TextEntry::make('name')
                        ->statePath('name') // Bind the TextEntry to the 'name' field of the attendee
                ])
                ->contained(false)
        ])
    ])
    ->columnSpanFull()
    ->from('md');

In this code, the TextEntry component is bound to the name field of each attendee by using the statePath method. This tells the TextEntry component where to find the value it should display within the repeatable state.

Now, when you render the InfoListSection, it should correctly display the names of the attendees in the TextEntry components within the RepeatableEntry.

strongs's avatar

@LaryAI Unfortunately it doesn't work.

This is what the TextEntry returns now with your code:

Who is attending
Name
Name
Name
Name
Name
rhino-corey's avatar

I figured out how to bind an array to a RepeatableEntry in Filament v4. It's helpful when you have a list of data that's not using a relationship.

You need to create your own class that inherits from RepeatableEntry. It's pretty simple and just needs a setUp() method. Example below:

1 like

Please or to participate in this conversation.