© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•3y ago•
2 replies
scalar

How to save data to two models in createOptionForm of Select at the same time?

Hello everyone, hope you are doing well!

There is a
Client 
Client 
model and a
Group
Group
model in the database.

Client model:
id
id
,
name
name

Group model:
id
id
,
name
name
,
client_id
client_id


When creating a new client using
createOptionForm
createOptionForm
, I want to create a new
group
group
based on
client_id
client_id
after creating a new
client
client
at the same time.

The problem is how to get
client_id
client_id
and then save it to the
Group
Group
model.


This is the select tag:

Forms\Components\Section::make()
    ->schema([
        Forms\Components\Select::make('client_id')
            ->relationship('client', 'name')
            ->label('Client')
            ->createOptionForm([
                Forms\Components\Section::make('')
                    ->schema([
                    Forms\Components\TextInput::make('name')
                        ->label('Client Name')
                        ->required()
                        ->maxLength(255)
                        ->columnSpan('full'),
                        
                Forms\Components\Section::make('group')
                    ->schema([
                    Forms\Components\TextInput::make('name')
                        ->label('Group Name')
                        ->required()
                        ->maxLength(255),
                })
        })
    })  
Forms\Components\Section::make()
    ->schema([
        Forms\Components\Select::make('client_id')
            ->relationship('client', 'name')
            ->label('Client')
            ->createOptionForm([
                Forms\Components\Section::make('')
                    ->schema([
                    Forms\Components\TextInput::make('name')
                        ->label('Client Name')
                        ->required()
                        ->maxLength(255)
                        ->columnSpan('full'),
                        
                Forms\Components\Section::make('group')
                    ->schema([
                    Forms\Components\TextInput::make('name')
                        ->label('Group Name')
                        ->required()
                        ->maxLength(255),
                })
        })
    })  

Thank you!
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

How to save data in select CreateOptionForm
FilamentFFilament / ❓┊help
3y ago
Select field createOptionForm - save and continue
FilamentFFilament / ❓┊help
10mo ago
How to save multiple select data to database
FilamentFFilament / ❓┊help
3y ago
How to connect multiple models of the same type?
FilamentFFilament / ❓┊help
3y ago