© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•3y ago•
4 replies
Log1x

Sort resource by relationship count – exception when empty

I have
Developers
Developers
that own
Software
Software
and I'm currently using
$table->defaultSort('software_count', 'desc')
$table->defaultSort('software_count', 'desc')
to sort my developers by the amount of software they have on my
DeveloperResource
DeveloperResource
.

If a developer does not have any software, I get an SQL exception for
Unknown column 'software_count' in 'order clause'
Unknown column 'software_count' in 'order clause'


Is there any way around that? It's just a simple
HasMany
HasMany
relationship.

I get this same issue with
Tables\Columns\TextColumn::make('software_count')
Tables\Columns\TextColumn::make('software_count')
but I think I can maybe do a
hidden()
hidden()
conditional check on it or something – but I also feel like I might be missing something. Ideally it'd just default to 0.
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

Sortable - Sort by far relationship
FilamentFFilament / ❓┊help
3y ago
How to sort table by relationship?
FilamentFFilament / ❓┊help
15mo ago
Error when trying to sort table by MorphTo relationship
FilamentFFilament / ❓┊help
15mo ago
How to sort TextColumn by relationship date attribute?
FilamentFFilament / ❓┊help
3y ago