У меня есть следующие таблицы:отношения многие ко многим с Laravel
сообщений {id, title, description}
Метки {id, name, description}
{post_id, tag_id}
post_tags
В Laravel я настроил отношения, как показано ниже. Я не уверен, как запросить мою сводную таблицу post_tags. Я получаю ошибку:
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'));
}
домой вид:
@foreach($post as $posts)
<tbody>
<tr>
<td> <a href="">{{$posts->tags->name}}</a> </td>
<td> </td>
<td> asked </td>
</tr>
</tbody>
@endforeach
Tag Модель:
public function post()
{
return $this->belongsToMany('App\Post');
}
Сообщение Модель:
public function tag()
{
return $this->belongsToMany('App\Tag');
}
Я не понимаю:?. Достаточно ли моих трех таблиц без этого с помощью Pivot ('id')? – steven
@steven да, три стола, две модели. –
Ах, я понимаю. Спасибо :) – steven