を働いていない私は、多くの関係に多くの基本的なを持っている:Laravel多くの多くは
Posts
Tags
私は、ピボットテーブルがpost_tag
呼ばれています。
:
@foreach($posts as $post)
{{ dd($post->tags) }}
@endforeach
私は次のエラーを取得する:ここで
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'tags.post_id' in 'where clause' (SQL: select * from
tags
wheretags
.post_id
= 1 andtags
.post_id
is not null) (View: C:\wamp\www\laravel\resources\views\posts\index.blade.php)
は私のモデルは以下のとおりです。
class Post extends Model
{
....
public function tags() {
return $this->hasMany(\App\Models\Tag::class);
}
}
class Tag extends Model
{
....
public function posts() {
return $this->belongsToMany(\App\Models\Post::class);
}
}
ここで何が起こっているかについてのアイデアはありますか?ピボットテーブルにデータがありますが、関係が正しく機能していないようです。
あなたは男です!私はポストが多くのタグを持つことができ、タグが多くのポストに属しているので意味があると思った。私はそれが許せば私は受け入れるだろう。ありがとう – user3574492