FilamentF
Filament2y ago
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(),

As you can see the call to $record->register->name is lazy loaded, which triggers an error for me because I am using 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?
Was this page helpful?