我创建一个这样的表:
帖子
id title
类别
id name
category_post
post_id
category_id
custom_value
在类别模型中:
public function posts()
{
return $this->belongsToMany(Post::class);
}
使用此命令:
$category = Category::find(1);
$posts = $category->posts()->get();
我可以得到所有的帖子。
每个相关帖子custom_value
都可以返回吗?category_post