请问一下dingo里边的collection集合,如果数据很多,怎么分页,或是只取集合十条数据,怎么写?

目前是是这样子获得评论集合的,如果评论很多,想分页或是只获取10条数据

    //评论
    public function includeComment(Content $content)
    {
        return $this->collection($content->comment,new CommentTransformer());
    }

```//分页
collection $content->comment 怎么分页,或是只取集合十条数据,怎么写?谢谢大家~

什么时候开始都不晚,学到老
《L01 基础入门》
我们将带你从零开发一个项目并部署到线上,本课程教授 Web 开发中专业、实用的技能,如 Git 工作流、Laravel Mix 前端工作流等。
《L03 构架 API 服务器》
你将学到如 RESTFul 设计风格、PostMan 的使用、OAuth 流程,JWT 概念及使用 和 API 开发相关的进阶知识。
最佳答案

在 Model 中的 hasMany 中对查询的数据进行 limit 限制即可。

例如:

/**
 * 获取博客文章的评论
 */
public function comments()
{
    return $this->hasMany('App\Comment')->limit(10);
}
2年前 评论
讨论数量: 2

在 Model 中的 hasMany 中对查询的数据进行 limit 限制即可。

例如:

/**
 * 获取博客文章的评论
 */
public function comments()
{
    return $this->hasMany('App\Comment')->limit(10);
}
2年前 评论

在获取 model 数据的时候做限制

$model->with(['comment' => function($qyery){
            $qyery->limit(1);
        }])->get()
2年前 评论

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!