Select does not load default value in Edit Action with relationship

Hello, Guys, I have a Select that when I enter the Edit Action it is not marking the default value that comes from the relationship. The relationship is being loaded normally and showing the value in the Select Label. I've already tried select with relationship and options and nothing. See the code as relationship:
Select::make('subpasta.parent.id')
->required()
->label(fn(Model $record): string => 'Pasta Principal: ' . $record->subpasta->parent->id)
->relationship(
'subpasta.parent',
'label',
modifyQueryUsing: fn(Builder $query) => $query->whereNull('parent_id')
)
//->options(Categoria::query()->whereNull('parent_id')->pluck('label', 'id'))
->searchable()
->placeholder('Selecione uma pasta.')
->loadingMessage('Carregando. Aguarde...')
->noSearchResultsMessage('Sem registros...')
->searchPrompt('Selecione uma pasta.')
->searchingMessage('Procurando...')
->preload()
->live()
->columnSpanFull(),
Select::make('subpasta.parent.id')
->required()
->label(fn(Model $record): string => 'Pasta Principal: ' . $record->subpasta->parent->id)
->relationship(
'subpasta.parent',
'label',
modifyQueryUsing: fn(Builder $query) => $query->whereNull('parent_id')
)
//->options(Categoria::query()->whereNull('parent_id')->pluck('label', 'id'))
->searchable()
->placeholder('Selecione uma pasta.')
->loadingMessage('Carregando. Aguarde...')
->noSearchResultsMessage('Sem registros...')
->searchPrompt('Selecione uma pasta.')
->searchingMessage('Procurando...')
->preload()
->live()
->columnSpanFull(),
The relationship is both belongsTo and it is working correctly, I tested it in tinker. $sub1->subpasta->parent
= App\Models\Categoria {#7159 id: 5, uuid: "0a3beef6-2d1c-46e0-af7e-915435c9fbec", parent_id: null, slug: "pasta-4", label: "Pasta 4", Does anyone know how to make this mark the default value correctly? Thanks.
No description
4 Replies
ChesterS
ChesterS9mo ago
Shouldn't it be something like Select::make('subpasta.parent_id') ?
joao nivaldo
joao nivaldoOP9mo ago
I did it this way and it continues the same way. Without displaying the default.
Select::make('subpasta.parent_id')
->required()
->label(fn(Model $record): string => 'Pasta Principal: ' . $record->subpasta->parent_id)
->relationship(
'subpasta.parent',
'label',
modifyQueryUsing: fn(Builder $query) => $query->whereNull('parent_id')
)
Select::make('subpasta.parent_id')
->required()
->label(fn(Model $record): string => 'Pasta Principal: ' . $record->subpasta->parent_id)
->relationship(
'subpasta.parent',
'label',
modifyQueryUsing: fn(Builder $query) => $query->whereNull('parent_id')
)
ChesterS
ChesterS9mo ago
Are the rest of the fields populated properly?
joao nivaldo
joao nivaldoOP9mo ago
Yes
Want results from more Discord servers?
Add your server