rtconner / laravel-tagging

Tag support for Laravel Eloquent models - Taggable Trait
MIT License
882 stars 168 forks source link

tagSlugs method #22

Closed alexgarrettsmith closed 9 years ago

alexgarrettsmith commented 9 years ago

Useful when checking for tags in a loop.

For example, I needed to use this in combination with Chosen (http://harvesthq.github.io/chosen/) to highlight tags selected on an article. Because tagNames gives a Str::title'd version as saved in the table, this can't be done cleanly.

rtconner commented 9 years ago

I was thinking people would/could just use the $model->tagged() function for this kind of scenario. But I can see the shortcut of using this.

alexgarrettsmith commented 9 years ago

@rtconner Yeah this is much more convenient. I was also considering extracting the following to another method to avoid duplication in both tagNames and tagSlugs, but I'll let you decide if you think this is better :)

$tagged = $this->tagged()->get(array('tag_slug'));

foreach($tagged as $tagged) {
  $tagSlugs[] = $tagged->tag_slug;
}
return $tagSlugs;
rtconner commented 9 years ago

I kept meaning to merge and then do upgrades. Apparently I haven't had time. So I'll just merge and do upgrades later.