F
Filament15mo ago
SLy

Duplicate queries in relation manager

I have a relation manager where I make some select field visible based on an eloquent model column filtered by a previous form field, when I check the queries in debugbar I see a lot of duplicated for the query in the visible() method, altthough nothing should repeat. Not sure what I am missing.
No description
1 Reply
SLy
SLyOP15mo ago
public function form(Form $form): Form
{
return $form
->schema([
Forms\Components\Select::make('transport_type_id')
->label('Transport type')
->translateLabel()
->relationship(name: 'transportType', titleAttribute: 'name->' . app()->getLocale())
->preload()
->live()
->required(),
Forms\Components\Select::make('port_id')
->label('Port')
->translateLabel()
->options(Port::pluck('name', 'id'))
->visible(fn (Get $get): bool => (bool) $get('transport_type_id') && TransportType::whereId($get('transport_type_id'))?->first()?->has_port)
->required(),
Forms\Components\Select::make('airport_id')
->label('Airport')
->translateLabel()
->options(Airport::pluck('name', 'id'))
->visible(fn (Get $get): bool => (bool) $get('transport_type_id') && TransportType::whereId($get('transport_type_id'))?->first()?->has_airport)
->required(),
Forms\Components\Select::make('import_export_type_id')
->label('Import/Export')
->translateLabel()
->relationship(name: 'importExportType', titleAttribute: 'name->' . app()->getLocale())
->required(),

}
public function form(Form $form): Form
{
return $form
->schema([
Forms\Components\Select::make('transport_type_id')
->label('Transport type')
->translateLabel()
->relationship(name: 'transportType', titleAttribute: 'name->' . app()->getLocale())
->preload()
->live()
->required(),
Forms\Components\Select::make('port_id')
->label('Port')
->translateLabel()
->options(Port::pluck('name', 'id'))
->visible(fn (Get $get): bool => (bool) $get('transport_type_id') && TransportType::whereId($get('transport_type_id'))?->first()?->has_port)
->required(),
Forms\Components\Select::make('airport_id')
->label('Airport')
->translateLabel()
->options(Airport::pluck('name', 'id'))
->visible(fn (Get $get): bool => (bool) $get('transport_type_id') && TransportType::whereId($get('transport_type_id'))?->first()?->has_airport)
->required(),
Forms\Components\Select::make('import_export_type_id')
->label('Import/Export')
->translateLabel()
->relationship(name: 'importExportType', titleAttribute: 'name->' . app()->getLocale())
->required(),

}
Want results from more Discord servers?
Add your server