/** * Filter model to subset with the given tags * * @param $tagNames array|string */ public function scopeWithAnyTag($query, $tagNames) { $tagNames = TaggingUtil::makeTagArray($tagNames); $tagNames = array_map($this->namespace . '\\TaggingUtil::slug', $tagNames); return $query->whereHas('tagged', function ($q) use($tagNames) { $q->whereIn('tag_slug', $tagNames); }); }