//文章
class essay extends Model
{
public function comment()
{
return $this->hasMany('App\comment')
}
}
//评论
class comment extends Model
{
public function essay()
{
return $this->belongsTo('App\essay')
}
}
如何取得每篇文章中的前10条评论
//这样写是错的!!! 只能取所有文章的所有评论的前10条
essay::with(['comment' => function($query) {
$query->take(10)
}])
求各位大佬帮帮忙
来自:https://segmentfault.com/a/11... 有两种方法,自己亲测过可行,但要注意以下。
//第一种方法,为作者编写的第三种方法。
改为
//第二种方法则为网址评论下的第一个网友(夜影)