© 2026 Hedgehog Software, LLC

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

Table: Multiple counting on same relationship

How can I have multiple counts on the same relation in one table?

TextColumn::make('applications_count')->counts('applications')->label('Applications'),

TextColumn::make('applications_count')->counts([
    'applications' => fn (Builder $query) => $query->where('completed', 1),
])->label('Completed applications'),
TextColumn::make('applications_count')->counts('applications')->label('Applications'),

TextColumn::make('applications_count')->counts([
    'applications' => fn (Builder $query) => $query->where('completed', 1),
])->label('Completed applications'),


This just shows the last column "Completed applications", but the name has to be
applications_count
applications_count
for the relation to work.
Solution
Perhaps you could try something like:
withCount
withCount


return $table
    ->modifyQueryUsing(function ($query) {
        $query->withCount([
            'applications',
            'applications as completed_applications_count' => function ($query) {
                $query->where('completed', 1),
            },
        ]);
    })
return $table
    ->modifyQueryUsing(function ($query) {
        $query->withCount([
            'applications',
            'applications as completed_applications_count' => function ($query) {
                $query->where('completed', 1),
            },
        ]);
    })

TextColumn::make('applications_count'),
TextColumn::make('completed_applications_count'),
TextColumn::make('applications_count'),
TextColumn::make('completed_applications_count'),
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

same relationship on multiple wizard steps
FilamentFFilament / ❓┊help
2y ago
multiple relationships with ->relationship()
FilamentFFilament / ❓┊help
3y ago
Multiple Layout Components with same Relationship
FilamentFFilament / ❓┊help
7mo ago
Count same relationship in multiple columns
FilamentFFilament / ❓┊help
2y ago