cviebrock / eloquent-taggable

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

Tagging not working #117

Closed btxtiger closed 3 years ago

btxtiger commented 3 years ago

When tagging a model, the function call fails with this. However the database entry seems to be created in taggable_tags, but not in taggable_taggables.

"cviebrock/eloquent-taggable": "^8.0",
"laravel/framework": "^8.12",
// From taggable_tags
tag_id,name,normalized,created_at,updated_at
5,peter parker,peter parker,2020-12-26 23:26:54,2020-12-26 23:26:54

$order->tag('peter parker');


```sh
Error

  Call to a member function contains() on string

  at vendor/cviebrock/eloquent-taggable/src/Taggable.php:131
    127▕         /** @var Tag $tag */
    128▕         $tag = app(TagService::class)->findOrCreate($tagName);
    129▕         $tagKey = $tag->getKey();
    130▕
  ➜ 131▕         if (!$this->getAttribute('tags')->contains($tagKey)) {
    132▕             $this->tags()->attach($tagKey);
    133▕         }
    134▕     }
    135▕
btxtiger commented 3 years ago

The issue occurred, because the existing table had a column "tags", which leads to a double occupancy. Renaming the column to something else instead "tags", gets it running. This might be a very important information in the setup notes.

cviebrock commented 3 years ago

Thanks for the info @btxtiger ... I'll update the documentation accordingly!