F
Filament10mo ago
gizmojo

Create select option form without relationship

Trying to use the createOptionForm so that it works without a relationship. This almost works apart from the select value/select option, is not updated even though the state is updated correctly.
Forms\Components\Select::make('group')
->native()
->required()
->options(function ($state): array {
$options = [];// fetch unique groups from DB
if ($state && ! isset($options[$state])) {
$options[$state] = $state;
}
return $options;
})
->createOptionForm(fn (): array => [
Forms\Components\TextInput::make('group')
])
->createOptionUsing(fn (array $data) => $data['group']),
Forms\Components\Select::make('group')
->native()
->required()
->options(function ($state): array {
$options = [];// fetch unique groups from DB
if ($state && ! isset($options[$state])) {
$options[$state] = $state;
}
return $options;
})
->createOptionForm(fn (): array => [
Forms\Components\TextInput::make('group')
])
->createOptionUsing(fn (array $data) => $data['group']),
1 Reply
bayusamara
bayusamara2w ago
have the same problem today i get the option from
$options = Product::select('name')->distinct()->get()->pluck('name','name');
$options = Product::select('name')->distinct()->get()->pluck('name','name');
and this createOptionUsing works for me
->createOptionForm([
Forms\Components\TextInput::make('name')
->required(),
])
->createOptionUsing(function ($data) use ($options) {
$options->push($data["name"]);
return $options->last();
})
->createOptionForm([
Forms\Components\TextInput::make('name')
->required(),
])
->createOptionUsing(function ($data) use ($options) {
$options->push($data["name"]);
return $options->last();
})
Want results from more Discord servers?
Add your server