© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•2y ago•
1 reply
Trauma Zombie

Relationship not saved when using createOptionUsing on Select input

Hi guys, I am trying to create subject via select input with createOptionForm. Inside that form is another relationship (seller), that is not saved when I chain createOptionUsing method. When I remove that method seller relationship is saved correctly, but I also need to save broker_id (user) to that subject, thats why I use createOptionUsing method. Can you help me?

Forms\Components\Select::make('subject_id')
    ->label(__('Subject'))
    ->relationship('subject', 'name')
    ->createOptionForm(static::getSubjectFields())
    ->createOptionUsing(function (array $data, Forms\Get $get): int {
        $user = User::find($get('broker_id')) ?? auth()->user();

        return $user->subjects()->create($data)->getKey();
    })
    ->saveRelationshipsUsing(function (Select $component, Model $record, $state) {
        dump($component, $record, $state);
    })
    ->saveRelationshipsBeforeChildrenUsing(function (Select $component, Model $record, $state) {
        dump($component, $record, $state);
    }),
Forms\Components\Select::make('subject_id')
    ->label(__('Subject'))
    ->relationship('subject', 'name')
    ->createOptionForm(static::getSubjectFields())
    ->createOptionUsing(function (array $data, Forms\Get $get): int {
        $user = User::find($get('broker_id')) ?? auth()->user();

        return $user->subjects()->create($data)->getKey();
    })
    ->saveRelationshipsUsing(function (Select $component, Model $record, $state) {
        dump($component, $record, $state);
    })
    ->saveRelationshipsBeforeChildrenUsing(function (Select $component, Model $record, $state) {
        dump($component, $record, $state);
    }),
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

Select not filled after createOptionUsing
FilamentFFilament / ❓┊help
3y ago
Using formatStateUsing on Select relationship
FilamentFFilament / ❓┊help
2y ago
createOptionUsing on select not called in livewire component
FilamentFFilament / ❓┊help
2y ago
createOptionUsing only works when Select is searchable
FilamentFFilament / ❓┊help
10mo ago