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: ```php Tables\Filters\Filter::make('is_blocked') ->label('Blocked users')...
Jump to solution
1 Reply
Solution
Martin Bojmaliev
Martin Bojmaliev13mo ago
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()
Want results from more Discord servers?
Add your server