ich die folgenden Tabellen:viele zu viele Beziehung mit Laravel
Beiträge {id, title, description}
Stichworte {id, name, description}
post_tags {post_id, tag_id}
In Laravel ich die Beziehungen nach oben wie unten festgelegt haben. Ich bin mir nicht sicher, wie ich meine Pivot-Tabelle post_tags abfragen soll. Ich erhalte eine Fehlermeldung aus:
SQLSTATE[42S02]: Base table or view not found: 1146 Table 'dev_match.post_tag' doesn't exist (SQL: select `tags`.*, `post_tag`.`post_id` as `pivot_post_id`, `post_tag`.`tag_id` as `pivot_tag_id` from `tags` inner join `post_tag` on `tags`.`id` = `post_tag`.`tag_id` where `post_tag`.`post_id` = 1)
Home Controller:
public function getindex(){
$post = Post::all();
return view('welcome', compact('post'));
}
Wohnansicht:
@foreach($post as $posts)
<tbody>
<tr>
<td> <a href="">{{$posts->tags->name}}</a> </td>
<td> </td>
<td> asked </td>
</tr>
</tbody>
@endforeach
Tag Model:
public function post()
{
return $this->belongsToMany('App\Post');
}
Beitrag Modell:
public function tag()
{
return $this->belongsToMany('App\Tag');
}
Ich verstehe nicht hinzufügen:. Sind meine drei Tische ohne dies mit Pivot ('id') genug? – steven
@steven ja, drei Tabellen, zwei Modelle. –
Ahh ich verstehe jetzt. Danke :) – steven