我的帖子和主题有多对多的 Laravel 关系:
我想获得帖子编号 > 10 from 某个话题
以下代码将获取特定主题的所有帖子:
$topic = Topic::where('id',$topic_id)->get()->first();
$posts= $topic->post;
现在如何获取帖子编号 > 10 ?
Models:
class Topic extends Eloquent{
public function post()
{
return $this->belongsToMany('post');
}
}
class Post extends Eloquent{
public function topic()
{
return $this->belongsToMany('Topic');
}
}
像这样:
Topic::with(array('posts' => function($q)
{
$q->where('id', '>', 10);
}))->where('id', $id)->first();
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)