Correct way to apply a `withCount()` and `->having()` in a SelectFilter?
I have a
Domain
that has many Sites
and I want to filter by the total number of sites each domain has. ie a drop down with eg 1, 2, 3 etc.
I feel I am sort of close, but can't seem to get the last part working;
This seems to produce the following SQL;
So it seems to not take ->having()
into account at all? Basically I'm able to get ->withCount('sites')
working, but unable to use it in the query.1 Reply
bump?
Solved. For anyone else wondering in the future this was the only way I could get it working. I was unable to get
->having()
working inside of ->modifyQueryUsing()
alone.
->options()
returns an array of site counts, eg [0,1,2,3]
ctype_digit()
was necessary because most casting doesn't play nicely with the string "0"
modifyQueryUsing()
is necessary to remove the where condition that filament applies by default, ie WHERE sites_count = 0