Skip to content

Commit 0ba803a

Browse files
authored
Merge pull request #111 from elbakly/patch-1
Update Taggable.php adding existing in groups
2 parents 239cb2f + eceb9a2 commit 0ba803a

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

src/Taggable.php

+17
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,23 @@ public static function existingTags()
292292
->orderBy('tag_slug', 'ASC')
293293
->get(array('tag_slug as slug', 'tag_name as name', 'tagging_tags.count as count'));
294294
}
295+
296+
/**
297+
* Return an array of all of the tags that are in use by this model
298+
* @param $groups Array with groups names
299+
* @return Collection
300+
*/
301+
public static function existingTagsInGroups(Array $groups)
302+
{
303+
return Tagged::distinct()
304+
->join('tagging_tags', 'tag_slug', '=', 'tagging_tags.slug')
305+
->join('tagging_tag_groups', 'tag_group_id', '=', 'tagging_tag_groups.id')
306+
->where('taggable_type', '=', (new static)->getMorphClass())
307+
->whereIn('tagging_tag_groups.name',$groups)
308+
->orderBy('tag_slug', 'ASC')
309+
->get(array('tag_slug as slug', 'tag_name as name', 'tagging_tags.count as count'));
310+
}
311+
295312

296313
/**
297314
* Should untag on delete

0 commit comments

Comments
 (0)