cartalyst / tags

A Tagging package that easily allows you to add tags to your Eloquent models.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Matching a tag based on slug can have side-effects

kostaspt opened this issue · comments

Hello,

I faced this issue in my project. Let's say a user adds a new tag #Test (or using any other symbol), then in the database we'll have:

slug | name
test | #Test

This looks fine until a user adds a tag Test. Then it'll match with the slug test that already exists, so the count will be 2 and return #Test as a name.

I'm not sure it can be fixed using the current package structure, except for cleaning up the name before adding it or returning the slug as the tag name to the user.

If you have any better ideas how to fix that, please share.

@kostaspt Are you sure you're using the package correctly? You should be utilizing two tables here. 'tags' and 'tagged'. 'tags' contain all the tags in your application. 'tagged' the relation of the tag to record.

Applications can have different contexts in which tags are used it is very possible that you can have tags with the same name related to separate models.

You'll want to take this into account when building your application and do any necessary logic to validate tags entering your application. i.e. if a user attempts to add a tag that already exists for the same model then you would do whatever logic you would like to happen such as returning a message to the user that the tag already exists, would you like to use it?

You can change the slug generator as described in the documentation https://cartalyst.com/manual/tags/2.0#slug-generator