public static function scopeWithTag(Builder $query, $tags, $type = 'slug') { $tags = (new static())->prepareTags($tags); return $query->whereHas('tags', function ($query) use($type, $tags) { $query->whereIn($type, $tags); }); }