ItemLabel Repeater Index In Input

Hello! I'm encountering what seems to be a basic issue with the following: I'm working on a "static" repeater where repeaters already have a default number of items, and users only need to fill in the values. I've managed to set the Label for each item based on its index. However, now I want to automatically fill in the default value of the attribute_id field with the ID of each item in the repeater. Any suggestions on how I could achieve this? Thank you very much!

                Grid::make('default')->schema([
                    Repeater::make('attributesRepeater')
                        ->relationship('attributesRepeater')
                        ->label('Atributos')
                        ->itemLabel(function ($uuid, $component) {
                            $keys = array_keys($component->getState());
                            $index = array_search($uuid, $keys);


                            $attributes = $this->getOwnerRecord()->attributes;

                            return $attributes[$index]->name;

                        })
                        ->schema([

                            TextInput::make('attribute_id')
                                ->hidden()
                                ->default($attributes[$index]->id),

                            Forms\Components\TextInput::make('value')
                                ->required()
                                ->label('Valor')
                                ->live(onBlur: true)
                                ->maxLength(255),

                        ])
                        ->grid(2)
                        ->defaultItems($this->getOwnerRecord()->attributes->count()),

                ]),
Was this page helpful?