© 2026 Hedgehog Software, LLC

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

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.
image.png
Filament banner
FilamentJoin
A powerful open source UI framework for Laravel • Build and ship admin panels & apps fast with Livewire
20,307Members
Resources
Was this page helpful?

Similar Threads

Recent Announcements

Similar Threads

Select with relationship and default value
FilamentFFilament / ❓┊help
2y ago
Select with relationship default
FilamentFFilament / ❓┊help
3y ago
Default value does not load correctly in MorphToSelect
FilamentFFilament / ❓┊help
3y ago
Select default relationship
FilamentFFilament / ❓┊help
2y ago