© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•2y ago•
6 replies
CT

How to eager load within a select using Form Builder?

I have the following:
Forms\Components\Select::make('registrar_username_id')
                            ->label('Registrar')
                            ->relationship(name: 'registrarUsername', titleAttribute: 'username')
                            ->getOptionLabelFromRecordUsing(fn(RegistrarUsername $record) => "{$record->registrar->name} -> {$record->username}")
                            ->preload()
                            ->searchable(),
Forms\Components\Select::make('registrar_username_id')
                            ->label('Registrar')
                            ->relationship(name: 'registrarUsername', titleAttribute: 'username')
                            ->getOptionLabelFromRecordUsing(fn(RegistrarUsername $record) => "{$record->registrar->name} -> {$record->username}")
                            ->preload()
                            ->searchable(),

As you can see the call to
$record->register->name
$record->register->name
is lazy loaded, which triggers an error for me because I am using
Model::shouldBeStrict()
Model::shouldBeStrict()
.
I realize that since it's an edit page there is no real benefit to eager loading, but I would like to keep strict mode active, but also remove this error.

Perhaps there is some way to modify or access the query before the page is loaded? Anyone got any ideas?
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

How to Eager Load Nested Relationship in table builder
FilamentFFilament / ❓┊help
2y ago
How to dynamically populate select option label using the Form Builder
FilamentFFilament / ❓┊help
3y ago
Eager load issue
FilamentFFilament / ❓┊help
2y ago
how to eager load in relationship manager
FilamentFFilament / ❓┊help
3y ago