Select createOptionForm not saved with the record

I have the following code which it works in v2 but not after upgrade to v3. The category saved and appeared in the select, but when save the form it's not saved with the created model.

Forms\Components\Select::make('category_id')
    ->label(__('validation.attributes.category'))
    ->relationship('category', 'name', fn ($query) => $query->with('parent'))
    ->getOptionLabelFromRecordUsing(fn ($record) => collect([$record->parent?->name, $record->name])->filter()->join(' - '))
    ->required()
    ->searchable()
    ->preload()
    ->createOptionForm([
        Forms\Components\TextInput::make('name')
            ->label(__('validation.attributes.name'))
            ->autocomplete(false)
            ->required()
            ->rule(fn ($livewire) => UniqueJsonRule::for(table: 'shop_categories', column: 'name', locale: $livewire->activeLocale)),
        Forms\Components\Select::make('parent_id')
            ->label(__('validation.attributes.parent_category'))
            ->placeholder(__('Leave it empty to be added as a parent category'))
            ->relationship('parent', 'name', fn (Builder $query) => $query->where('parent_id', null))
            ->getOptionLabelFromRecordUsing(fn ($record) => $record->name)
            ->searchable()
            ->preload(),
    ])
    ->createOptionUsing(function ($component, $data, $form) {
        $record = $component->getRelationship()->getRelated();
        $record->fill($data);
        $record->save();

        $form->model($record)->saveRelationships();

        return $record->global_id;
    })
Was this page helpful?