Skip to content

Commit

Permalink
Update Taggable.php adding existing in groups
Browse files Browse the repository at this point in the history
Added existingTagsInGroup Funtion Take array with groups name ["GroupA","GroupB"] and return Tags in those groups
example Student::existingTagsInGroups(["basket-ball","foot-ball"]); result is collection of tags ["Playmaker","Defenders",etc..]
  • Loading branch information
elbakly authored Aug 21, 2016
1 parent 239cb2f commit eceb9a2
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 eceb9a2

Please sign in to comment.