spatie / laravel-tags

Add tags and taggable behaviour to your Laravel app

Home Page:https://freek.dev/609-an-opinionated-tagging-package-for-laravel-apps

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Cannot attach tag to model

danielthomascarr opened this issue · comments

followed installation instructions using Laravel 7 and added to model

namespace App;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
use Spatie\Tags\HasTags;

class Product extends Model
{
    use HasTags;
}

used Tinker
$product = App\Product::find(1); created a tag manually in database, tried to attach

$product->attachTag('tag4');

but get error

BadMethodCallException with message 'Call to undefined method App/Product::attac
hTag()'

I think the model is not attached because I can create a tag using

$product->attachTag(\Spatie\Tags\Tag::findOrCreate('tag3', 'something'));

which creates the tag but doesn't attach it to the model and don't know why?

composer dumpautoload to the rescue