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.
2 Replies
joao nivaldo
joao nivaldo7mo ago
No description
No description
joao nivaldo
joao nivaldo7mo ago
The problem was that when the default value is marked as suspended and my rule forces it not to display it, then the component does not have the label to display it instead of the id. Damn, I had a hard time watching this.