0

I have a repeater that contains a select (option) and a multi-select (values) where I added a create form for both so the user can add an unexisting option/value.

But values are option dependent so I am trying to pass the option_id from the repeater to the create form modal and I'm just stuck with null when I try to die dump data.

Repeater::make('Product Options')
                    ->relationship('productOptions')
                    ->schema([
                        Select::make('option_id')
                            ->reactive()
                            ->relationship('option','name')
                            ->columnSpan(1)
                            ->createOptionForm([
                                TextInput::make('name')
                                    ->required(),
                                ]),
                        Select::make('optionValues')
                            ->multiple()
                            ->preload()
                            ->relationship('optionValues','name', fn (Builder $query,callable $get) => $query->where('option_id',$get('option_id')))
                            ->createOptionForm([
                                Select::make('option_id')
                                    ->relationship('option','name'),
                                TextInput::make('name')
                                    ->required(),
                                ])
                            ->columnSpan(3)
                            ->reactive()
                        ])

I want the create form on the values to be like the following code:

Select::make('optionValues')
                            ->multiple()
                            ->preload()
                            ->relationship('optionValues','name', fn (Builder $query,callable $get) => $query->where('option_id',$get('option_id')))
                            ->createOptionForm([
                                TextInput::make('name')
                                    ->required(),
                                ])
                            ->columnSpan(3)
                            ->reactive()

where the option_id is just retrieved from the repeater.

Ryan M
  • 18,333
  • 31
  • 67
  • 74

1 Answers1

1

To pass data to forms just use this:

->createOptionForm(fn ($get) => [
  Select::make('option_id')
      ->relationship('option','name')
      ->default($get('option_id')),
  TextInput::make('name')
      ->required(),
])