© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•3y ago•
2 replies
Pablo Torres

How to avoid extra queries created when related data is displayed?

The following adds a tooltip to show:
"booking xyz has 1 deal"
Or,
"booking xyz has 2 deals"
(implementing Str::plural) with the number of records in the related "deals" table.
Tables\Columns\TextColumn::make('deals_count')->counts('deals')
    ->color('primary')
    ->icon('heroicon-o-thumb-up')
    ->label('Deals')
    ->tooltip(fn (Booking $record): string => $record->name . " has " . $record->deals()->count() . " " . Str::plural('deal', $record->deals()->count())),
Tables\Columns\TextColumn::make('deals_count')->counts('deals')
    ->color('primary')
    ->icon('heroicon-o-thumb-up')
    ->label('Deals')
    ->tooltip(fn (Booking $record): string => $record->name . " has " . $record->deals()->count() . " " . Str::plural('deal', $record->deals()->count())),

The above adds two extra queries, how can I still show the icon with the records count but avoid extra queries?
Any advice is much appreciated.
Thank you.
queries.jpg
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 avoid duplicate queries
FilamentFFilament / ❓┊help
2y ago
No data displayed
FilamentFFilament / ❓┊help
2y ago
Optimizing Queries in FileUpload – How to Avoid Duplicate Calls?
FilamentFFilament / ❓┊help
14mo ago
How to output related column data to table?
FilamentFFilament / ❓┊help
3y ago