Filter Assets by Tags with AssetQueryBuilder with wherehas #7520
-
I'm creating a paginated grid of all assets in a container with a filter function. The assets are tagged and i'm trying to build a query which checks for the filtered tags. $arrayOfFilteredTerms = ['tags::foo', 'tags::bar'];
Asset::query()->where('container', 'media')->whereHas('tags', function($q) use ($arrayOfFilteredTerms){
$q->whereIn('id', $arrayOfFilteredTerms);
}); which results in
When the AssetQueryBuilder doesn't work with "whereHas", I have to filter my collection after getting the query. This collides with the pagination - which limits the query results before they get filtered - and besides it's very slow. Is there any chance to filter assets by tags directly in the query? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
We don't support But you can just treat it as json. Asset::query()->where('container', 'media')->whereJsonContains('tags', $arrayOfFilteredTerms) |
Beta Was this translation helpful? Give feedback.
We don't support
whereHas
at the moment, as you've noted.But you can just treat it as json.