cviebrock / eloquent-taggable

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

Multiple tag types #30

Closed lorvent closed 6 years ago

lorvent commented 8 years ago

Hi,

I have Portfolio model where i want to use eloquent-taggable for 2 field types

  1. technologies
  2. tags

but the problem is since we have to do $portfolio->add(); its not able to distinguish whether a tag related to technologies or tags.

can you show me a better way to achieve this?

Thanks.

cviebrock commented 8 years ago

Hrmm ... I don't think something like this is possible right now. Let me think about how best to do it, and I'll add it to the next version.

Thanks!

lorvent commented 8 years ago

Hmm, thanks for the response.

so far we did like this

Portfolio has 2 tag sections technologies and tags

so created 2 intermediate models Technology.php, Tag.php and tables and storing relation info.

its not a good approach but the only possible hack for timebeing.

skattabrain commented 8 years ago

+1 - I could use this as well... I have a situation where my asset will have several types of tags. For example... color, medium, subject.

In a previous app before the Laravel days, I approached it by making tags like this... "Color / Red", "Color / Blue", "Subject / Abstract" and "Subject / Fine Art".

I would then explode them out using the / and I could essentially have my input control like this...

Label - Color Tag List - Red, Blue

Label - Subject Tag list - Abstract, Fine Art

It allowed me to have 1 table with 1 column for the tag. Then in my UI, I would explode the tag by / and display the last item in the array for the tag and the first to show the category.

Might not be practical for this design (which is really nice btw)

elephantux commented 8 years ago

+1

Cigoler commented 6 years ago

I notice there is a taggable_type in the taggable_taggables table. Is it possible to differentiate between models therefore? So you could have a product model, and an articles model and limit searches between t hem that way?

wemteqdev commented 6 years ago

It would be great if it provide tag context. $video->tag(['love'], 'feature');

VideoModel::tagsWithContext('feature'); VideoModel::tagsWithContext('action'); VideoModel::tagsWithContext('animation');

cviebrock commented 6 years ago

I like that approach, @avasiliev87 . I'll definitely add this to the next major version. Or feel free to submit a PR!