© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•3y ago•
3 replies
joao nivaldo

Default value does not load correctly in MorphToSelect

Hello, I need some guidance from you, when I apply the modifyOptionQueryUsing method on the default value of the second select it shows the id instead of the chosen label. If I remove the modifyOptionQueryUsing method it displays the default value correctly. My code is like this:
MorphToSelect::make('dono')
->types([MorphToSelect\Type::make(Imobiliaria::class)
  ->getOptionLabelFromRecordUsing(fn(Imobiliaria $record): string => "{$record->fantasia_contato}")
  ->modifyOptionsQueryUsing(fn(Builder $query) => $query->where('ativo', StatusEnum::ACTIVE->value))
  ->titleAttribute('fantasia_contato'),
MorphToSelect\Type::make(Proprietario::class)
  ->modifyOptionsQueryUsing(fn(Builder $query) => $query->where('ativo', StatusEnum::ACTIVE->value))
  ->titleAttribute('razao_nome'),
])
->label('Pertencente a')
->searchable()
->preload()
->required()
->columnSpanFull(),
MorphToSelect::make('dono')
->types([MorphToSelect\Type::make(Imobiliaria::class)
  ->getOptionLabelFromRecordUsing(fn(Imobiliaria $record): string => "{$record->fantasia_contato}")
  ->modifyOptionsQueryUsing(fn(Builder $query) => $query->where('ativo', StatusEnum::ACTIVE->value))
  ->titleAttribute('fantasia_contato'),
MorphToSelect\Type::make(Proprietario::class)
  ->modifyOptionsQueryUsing(fn(Builder $query) => $query->where('ativo', StatusEnum::ACTIVE->value))
  ->titleAttribute('razao_nome'),
])
->label('Pertencente a')
->searchable()
->preload()
->required()
->columnSpanFull(),

Thanks.
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

Default MorphToSelect value
FilamentFFilament / ❓┊help
2y ago
MorphToSelect default value value
FilamentFFilament / ❓┊help
6mo ago
Select does not load default value in Edit Action with relationship
FilamentFFilament / ❓┊help
2y ago
the image does not load correctly
FilamentFFilament / ❓┊help
3y ago