2017-02-27 1 views
0

Ich habe setzen die folgenden Beziehungen auf:kann nicht anhängen() -Methode in Laravel

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

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

und Pivot-Tabelle wie folgt aus:

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'); 
    }); 

jetzt, habe ich Attach() -Methode:

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

aber das nicht funktioniert und ich bekomme diese Fehlermeldung:

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

Antwort

1

Sieht aus, als ob Sie die falsche Klasse importiert haben, die entspricht Tag :: class.

Es sollte wohl so etwas wie dieses:

use App\Tag;

statt:

use phpDocumentor\Reflection\DocBlock\Tag;

+0

vielen Dank – narges