narges narges -4 years ago 122
PHP Question

cannot using attach() method in laravel

I have the following relations set up:

public function notes()
return $this->belongsToMany(Note::class);

public function tags()
return $this->belongsToMany(Tag::class);

and pivot table like this:

Schema::create('note_tag', function (Blueprint $table) {
$table->engine = 'InnoDB';

now, i used Attach() method:


but that doesn't work and I get this error:

Cannot instantiate interface phpDocumentor\Reflection\DocBlock\Tag

Answer Source

Looks like you've imported the wrong class that corresponds to Tag::class.

It should probably be something like this:

use App\Tag;

instead of:

use phpDocumentor\Reflection\DocBlock\Tag;

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download