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
https://filamentphp.com/docs/3.x/forms/fields/select#customizing-new-option-creation