I'm confused about the Laravel API and its many to many relationship model.
There are the following tables:
posts
tags
post_tag
And I want to find posts which have tagId = 123
Is there simple source code similar to the following?
$posts= Post::find()->pivot->tag(123);
Thanks.
You should specify the method in Tag model:
public function posts()
{
return $this->belongsToMany('App\Post');
}
Then you can find posts which have tagId = 123
$posts = Tag::find(123)->posts();