© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•3y ago•
3 replies
Martin Bojmaliev

Filter doesn't work when having `having` in the query

In UserResource i want to filter users that have more then X number of device tokens.

I'm doing something like:

Tables\Filters\Filter::make('is_blocked')
  ->label('Blocked users')
  ->query(fn ($query) => $query
    ->withCount('deviceTokens')
    ->having('device_tokens_count', '>=', 4)
  )
  ->toggle(),
Tables\Filters\Filter::make('is_blocked')
  ->label('Blocked users')
  ->query(fn ($query) => $query
    ->withCount('deviceTokens')
    ->having('device_tokens_count', '>=', 4)
  )
  ->toggle(),

But when I activate the filter the SQL query that's being sent to database doesn't seems to be changed.


Normally in Laravel thinker when I write something like:
 User::query()->withCount('deviceTokens')->having('device_tokens_count', '>=', 4)->get()
 User::query()->withCount('deviceTokens')->having('device_tokens_count', '>=', 4)->get()


It works fine.

Any ideas ?
Solution
I solved it using:

Tables\Filters\Filter::make('is_blocked')
  ->label('Blocked users')
  ->query(fn (Builder $query) => $query->has('deviceTokens', '>=', DeviceToken::maxAllowedTokens) )
  ->toggle()
Tables\Filters\Filter::make('is_blocked')
  ->label('Blocked users')
  ->query(fn (Builder $query) => $query->has('deviceTokens', '>=', DeviceToken::maxAllowedTokens) )
  ->toggle()
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

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Releationship doesn't seem to work in Filter
FilamentFFilament / ❓┊help
3y ago
Filter test FAILED `filterTable` doesn't work
FilamentFFilament / ❓┊help
13mo ago
Show Indicator on Custom Filter doesn't work
FilamentFFilament / ❓┊help
2y ago
input in modal doesn't work
FilamentFFilament / ❓┊help
3y ago