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

stevepurcell's avatar

Filament: display the id of each repeater

I have a set of repeaters and would like to display the ID of each one to help the user know which one they were working with. I would like to place this in the ->itemLabel('1st place')

I apologize, I am struggling with adding an image showing what the page looks like.

return [
            Forms\Components\Repeater::make('players')
                ->schema([
                    Forms\Components\Select::make('name')
                    ->label('Choose driver:')
                        ->options(function (callable $get) {
                            $players = $get('../../players');
                            $idsAlreadyUsed = [];

                            foreach($players as $repeater) {
                                if(! in_array($repeater['name'], $idsAlreadyUsed)
                                    && $repeater['name'] !== null
                                    && $repeater['name'] != $get('name')) {
                                    $idsAlreadyUsed[] = $repeater['name'];
                                }
                            }

                            return Player::whereNotIn('id', $idsAlreadyUsed)->pluck('name', 'id')->toArray();
                        })
                        ->reactive()
                        ->required()
                        
                ])
                ->itemLabel('1st Place')
                ->disableLabel()
                ->defaultItems(10)
                ->disableItemCreation()
                ->disableItemDeletion()
                ->disableItemMovement()
        ];
0 likes
4 replies
medge's avatar

The ID (if you mean the unique one for each repeater) isn't particularly human-friendly. I'm in the process of understanding whether it can be set upon creation.

array:4 [ "data" => array:14 [ "data" => array:15 [ "services" => array:1 [ "f7d3132c-6ce6-490a-ae53-88f7cfb5d71c" => array:1 [ "testfield" => null ] ]

You can, however, do things with the data potentially by using

     ->mutateFormDataUsing(function (array $data): array {
                                                        // This is an opportunity to convert the form data into what OrderService expects
                                                        $data['user_id'] = auth()->id();
                                                        return $data;
                                                    }

There are also events for beforeFormFilled(), afterFormFilled(), beforeFormValidated(), afterFormValidated(), before() and after()

AbdullahAyana's avatar

i use this way

//before form () define
 protected static ?int $indexRepeater = 1;

 Forms\Components\Repeater::make('options')
                    ->label(__('Options'))
                    ->schema([
                        Forms\Components\TextInput::make('option.en')
                            ->label(__('Option In English'))
                            ->required(),
                        Forms\Components\TextInput::make('option.ar')
                            ->label(__('Option In Arabic'))
                            ->required(),
                    ])
                    ->itemLabel(fn() => __('Option') . ' ' . ++self::$indexRepeater)
                    ->deleteAction(function ($action) {
                        --self::$indexRepeater;
                        return $action;
                    })
1 like

Please or to participate in this conversation.