© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•3y ago•
8 replies
MohamedSabil83

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;
    })
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;
    })
Filament banner
FilamentJoin
A powerful open source UI framework for Laravel • Build and ship admin panels & apps fast with Livewire
20,307Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

createOptionForm is not saving the created record
FilamentFFilament / ❓┊help
3y ago
Select::createOptionForm not always work
FilamentFFilament / ❓┊help
3y ago
Select::createOptionForm fill?
FilamentFFilament / ❓┊help
16mo ago
select will not open createOptionForm modal
FilamentFFilament / ❓┊help
3y ago