如何在Laravel中创建分页?
我的模型:
文章(Post)
我的模型:
文章(Post)
function comments() {
return $this->hasMany('Comment')
->orderBy('created_at', 'desc');
}
评论
function posts(){
return $this->belongsTo('Post');
}
用户
function posts(){
return $this->hasMany('Post');
}
function comments(){
return $this->hasMany('Comment');
}
用户控制器
$user = User::find(1); //this will give me all the user's post and comment details
//i know I can do $user = User::paginate(30) to get 30 user per page
我想要实现的目标
我想创建一个每页显示10条评论的分页。
提前感谢您的帮助。