© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•15mo ago•
6 replies
Prodex

How to access attributes of a selected record, without duplicate queries?

Hi, I want to display additional information of the selected company using Placeholders. But each time I use
Company::find($get('company_id'))
Company::find($get('company_id'))
an additonal query will be fired. How can I prevent this?

                        Forms\Components\Repeater::make('excursionsCompanies')
                            ->label(__('excursion.excursionsCompanies'))
                            ->addActionLabel(__('excursion.add_company'))
                            ->relationship()
                            ->itemLabel(fn (array $state): ?string => Company::find($state['company_id'])?->name)
                            ->orderColumn('sort')
                            ->schema([
Forms\Components\Select::make('company_id')
                                    ->label(__('company.singular'))
                                    ->live()
                                    ->searchable()
                                    ->relationship('company', 'name')
                                    ->required(),

                                Forms\Components\Placeholder::make('company_address')
                                    ->label(__('company.address'))
                                    ->hidden(fn (Get $get) => ! $get('company_id'))
                                    ->content(fn (Get $get) =>     Company::find($get('company_id'))?->fullAddress),
];
                        Forms\Components\Repeater::make('excursionsCompanies')
                            ->label(__('excursion.excursionsCompanies'))
                            ->addActionLabel(__('excursion.add_company'))
                            ->relationship()
                            ->itemLabel(fn (array $state): ?string => Company::find($state['company_id'])?->name)
                            ->orderColumn('sort')
                            ->schema([
Forms\Components\Select::make('company_id')
                                    ->label(__('company.singular'))
                                    ->live()
                                    ->searchable()
                                    ->relationship('company', 'name')
                                    ->required(),

                                Forms\Components\Placeholder::make('company_address')
                                    ->label(__('company.address'))
                                    ->hidden(fn (Get $get) => ! $get('company_id'))
                                    ->content(fn (Get $get) =>     Company::find($get('company_id'))?->fullAddress),
];

In the example above, 2 duplicate queries are created.

Thank you!
Solution
->content(fn (Get $get) =>     static::getCompany($get('id'))
->content(fn (Get $get) =>     static::getCompany($get('id'))


static function getCompany(int|string $id) {
   return once(fn () => Company::find($get('company_id'))?->fullAddress));
}
static function getCompany(int|string $id) {
   return once(fn () => Company::find($get('company_id'))?->fullAddress));
}
Jump to solution
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

How to avoid duplicate queries
FilamentFFilament / ❓┊help
2y ago
Preset attributes according to selected tab/previously created record
FilamentFFilament / ❓┊help
17mo ago
Duplicate queries
FilamentFFilament / ❓┊help
2y ago
HasCellState duplicate queries
FilamentFFilament / ❓┊help
2y ago