© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•2y ago•
4 replies
Arjan

QueryBuilder with an relationship->counts()

Hi,
I am using this column with a count of related Assets (hasMany relationship) in my table:

TextColumn::make('assets_count')
->numeric()
->label('Assets')
->counts('assets'),

I now want to make a filter for this column using Querybuilder:

NumberConstraint::make('assets_count')
->relationship(
name: 'assets',
titleAttribute: 'id',
modifyQueryUsing: fn(Builder $query) => $query->count(),
)
->label("Assets"),

However this NumberContraint is not working and throws this error:

SQLSTATE[42P01]: Undefined table: 7 ERROR: missing FROM-clause entry for table "series" LINE 1: select count() as aggregate from "assets" where "series"."i... ^
SELECT count(
) AS aggregate FROM "assets" WHERE "series"."id" = "assets"."series_id"

Please help!

Thanks!
Solution
try remove
modifyQueryUsing
modifyQueryUsing

this works for me
NumberConstraint::make('likes_count')
  ->relationship('likes', 'id')
  ->integer(),
NumberConstraint::make('likes_count')
  ->relationship('likes', 'id')
  ->integer(),
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

->counts() on relationship
FilamentFFilament / ❓┊help
3y ago
counts not working on relationship
FilamentFFilament / ❓┊help
3y ago
Select filter in QueryBuilder for nested relationship
FilamentFFilament / ❓┊help
3mo ago