2017-02-27 36 views
0

方法,我有以下關係成立:不能使用附加()在laravel

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

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

和數據透視表是這樣的:

Schema::create('note_tag', function (Blueprint $table) { 
     $table->engine = 'InnoDB'; 
     $table->integer('note_id')->unsigned()->index(); 
     $table->foreign('note_id')->references('id')->on('tags')->onDelete('cascade')->onUpdate('cascade'); 
     $table->integer('tag_id')->unsigned()->index(); 
     $table->foreign('tag_id')->references('id')->on('notes')->onDelete('cascade')->onUpdate('cascade'); 
    }); 
現在

,我使用attach()方法:

$note->tags()->attach($tagsIds); 

但這不起作用,我得到這個錯誤:

[Symfony\Component\Debug\Exception\FatalErrorException] Cannot instantiate interface phpDocumentor\Reflection\DocBlock\Tag

回答

1

看起來你已經輸入了與對應的錯誤類Tag :: class

這也許應該是這樣的:

use App\Tag;

代替:

use phpDocumentor\Reflection\DocBlock\Tag;

+0

非常感謝你 – narges