Skip to content

Commit

Permalink
Merge pull request #111 from elbakly/patch-1
Browse files Browse the repository at this point in the history
Update Taggable.php adding existing in groups
  • Loading branch information
rtconner authored Aug 22, 2016
2 parents 239cb2f + eceb9a2 commit 0ba803a
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/Taggable.php
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,23 @@ public static function existingTags()
->orderBy('tag_slug', 'ASC')
->get(array('tag_slug as slug', 'tag_name as name', 'tagging_tags.count as count'));
}

/**
* Return an array of all of the tags that are in use by this model
* @param $groups Array with groups names
* @return Collection
*/
public static function existingTagsInGroups(Array $groups)
{
return Tagged::distinct()
->join('tagging_tags', 'tag_slug', '=', 'tagging_tags.slug')
->join('tagging_tag_groups', 'tag_group_id', '=', 'tagging_tag_groups.id')
->where('taggable_type', '=', (new static)->getMorphClass())
->whereIn('tagging_tag_groups.name',$groups)
->orderBy('tag_slug', 'ASC')
->get(array('tag_slug as slug', 'tag_name as name', 'tagging_tags.count as count'));
}


/**
* Should untag on delete
Expand Down

0 comments on commit 0ba803a

Please sign in to comment.