© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•3y ago•
7 replies
usmcgator

counts not working on relationship

I'm trying to add a column that shows a count of the related records. This code correctly displays JSON output of the related records, so I know it's getting them correctly, but counts() doesn't work.

This gets results from the relationship:

TextColumn::make('goals'),
TextColumn::make('goals'),

This fails with: Call to a member function goals() on null

TextColumn::make('goals_count')->counts("goals"),
TextColumn::make('goals_count')->counts("goals"),

Here are the relationships:
    public function mission()
    {
        return $this->belongsTo(Mission::class, 'mission_id', 'id');
    }

    public function goals()
    {
        return $this->mission->goals()->with('mission');
    }
    public function mission()
    {
        return $this->belongsTo(Mission::class, 'mission_id', 'id');
    }

    public function goals()
    {
        return $this->mission->goals()->with('mission');
    }

Where am I going wrong?
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

->counts() on relationship
FilamentFFilament / ❓┊help
3y ago
Restore not working on Relationship
FilamentFFilament / ❓┊help
2y ago
QueryBuilder with an relationship->counts()
FilamentFFilament / ❓┊help
2y ago