cviebrock / eloquent-taggable

Easily add the ability to tag your Eloquent models in Laravel.
MIT License
537 stars 72 forks source link

Tags merge #47

Closed antonkomarev closed 7 years ago

antonkomarev commented 7 years ago

This is an enhancement which could be helpful to manage unwanted typos or spellings of the words and remove tags duplicates. For example you have 100 tags formula-1 and 20 tags formula1. You want to leave only formula-1 tag as a valid one and replace all the formula1 tags in all the entities with formula-1. Another one example is merge of plural and singular tags friend or friends.

Here what configuration options I could find usable:

I suppose there should be separate database table which will keep all the merge rules.

cviebrock commented 7 years ago

This can partially be accomplished with the normalizer configuration: if you create a function or class method that can convert formula-1 and formula1 into a normalized string, or friends into friends, then this is already supported when tagging new models.

If you want to do this after the fact (i.e. you already have models that are tagged one way and you want to convert them), then I can add a method to the service class, something like:

TagService::rename('formula1', 'formula-1', \App\Articles::class);

The third argument is an optional classname to restrict the renaming.

Does that make sense?

cviebrock commented 7 years ago

This is in place on the new 3.x branch (in dev right now). Feel free to checkout dev-master and give it a try.