CreateOptionForm in Repeater with dependent select component

I have a Repeater with dependent addon_name select field that ties to the addon_type field. Now I want users to be able to add new add-on name options to the list, like others, the problem is I didn't define the relationship() for the addon_name from the get-go. Bcs as you know I use the customization technique for the dependent name options. How do I go about this?

Select::make('addon_id')->label('Add-on Name')
                    ->options(function (callable $get) {
                        $type = $get('type');

                        if (!$type) {
                            return Addon::pluck('name', 'id');
                        }
                        return Addon::where('type', $type)->pluck('name', 'id');
                    })
                    ->searchable()
                    ->reactive()
                    ->createOptionForm([
                        Select::make('type')->label('Add-on Type')
                            ->options(Addon::pluck('type', 'type'))
                            ->placeholder('Select type')
                            ->required(),
                        TextInput::make('name')->required()
                    ])
                    ->required(),
Solution
->createOptionForm([
    Select::make('type')->label('Add-on Type')
        ->options(Addon::pluck('type', 'type'))
        ->required(),
    TextInput::make('name')->required()
])                            
->createOptionUsing(function (array $data) {
    $addon = Addon::create($data);
    return $addon->id;
})
?
Was this page helpful?