© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•2y ago•
15 replies
lacymj

Counting relationships

I have a simple relationship between an Entry and a Jockey.

class Entry extends Model
{
public function jockey(): BelongsTo
{
return $this->belongsTo(Jockey::class);
}
}

class Jockey extends Model
{
public function entries(): hasMany
{
return $this->hasMany(Entry::class);
}
}

I created filament resources for both models and am trying to get the relationship counts on the table list. It works great on the JockeyResource with this:

Tables\Columns\TextColumn::make('entries_count')
->label('Entry Count')
->counts('entries'),

BUT, when I try to get the same entry count on the EntryResource using what I "think" should work:

Tables\Columns\TextColumn::make('jockey.entries_count')
->label('Entry Count')
->counts('jockey.entries'),

I get this error

Call to undefined method App\Models\Entry::jockey.entries()

What's interesting is that if I take off the count options and just do this:

Tables\Columns\TextColumn::make('jockey.entries')
->label('Entry Count'),

I get the entire Entry record for all the correct entries

Any ideas how I can just get the count? I don't need the entire record returned.
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

Counting relationships performance
FilamentFFilament / ❓┊help
3y ago
relationships counting-relationships with date filters
FilamentFFilament / ❓┊help
2y ago
How to test Counting relationships
FilamentFFilament / ❓┊help
3y ago
Saving relationships
FilamentFFilament / ❓┊help
11mo ago