© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•8mo ago•
4 replies
Jamie Cee

Select relationship automatically select value after creation

Correct me if im wrong, but if I have the option to create a new record in my relationship select... does it not automatically select it upon creation

                                Forms\Components\Select::make('tags')
                                    ->relationship('tags', 'name')
                                    ->multiple()
                                    ->preload()
                                    ->searchable()
                                    ->createOptionForm([
                                        Forms\Components\TextInput::make('name')
                                            ->label('Create New Tag')
                                            ->unique(ignoreRecord: true)
                                            ->maxLength(255),
                                        Forms\Components\TextInput::make('description')
                                            ->label('Description')
                                            ->nullable()
                                            ->maxLength(500),
                                    ])
                                    ->createOptionUsing(function (array $data) {
                                        return Tag::create([
                                            'name' => $data['name'],
                                            'slug' => Str::slug($data['name']),
                                            'description' => $data['description'] ?? null,
                                        ]);
                                    }),
                                Forms\Components\Select::make('tags')
                                    ->relationship('tags', 'name')
                                    ->multiple()
                                    ->preload()
                                    ->searchable()
                                    ->createOptionForm([
                                        Forms\Components\TextInput::make('name')
                                            ->label('Create New Tag')
                                            ->unique(ignoreRecord: true)
                                            ->maxLength(255),
                                        Forms\Components\TextInput::make('description')
                                            ->label('Description')
                                            ->nullable()
                                            ->maxLength(500),
                                    ])
                                    ->createOptionUsing(function (array $data) {
                                        return Tag::create([
                                            'name' => $data['name'],
                                            'slug' => Str::slug($data['name']),
                                            'description' => $data['description'] ?? null,
                                        ]);
                                    }),
Solution
add ->getKey() in return maybe?
https://filamentphp.com/docs/3.x/forms/fields/select#customizing-new-option-creation
Select - Forms - Filament
Jump to solution
Filament banner
FilamentJoin
A powerful open source UI framework for Laravel • Build and ship admin panels & apps fast with Livewire
20,307Members
Resources
Was this page helpful?

Similar Threads

Recent Announcements

Similar Threads

Select with relationship and default value
FilamentFFilament / ❓┊help
2y ago
How to get record of select relationship automatically
FilamentFFilament / ❓┊help
3y ago
Select relationship
FilamentFFilament / ❓┊help
3y ago