在分页功能中使用限制参数 [英] Using limit parameter in paginate function

查看:164
本文介绍了在分页功能中使用限制参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在paginate()函数中使用'limit'参数?

Is it possible to use 'limit' parameter in paginate() function?

我正在尝试:

$users->where(...)->limit(50)->paginate($page)

...现在,如果数据库中有100个用户,则分页功能的响应将全部为100个用户,而不是50个(或用户使用限制参数定义。)

...and now, if I have 100 users in the database then the response from paginate function will be all 100 users instead of 50 (or number of users defined with limit parameter).

因此,我的问题是:使用分页功能时是否可以实现限制参数?

So, my question is: is it possible to implement limit parameter when I use paginate function?

推荐答案

否,使用分页时不可能限制查询。

No, it's not possible to limit the query when using pagination.

查询分页使用<$ c在内部使用$ c> skip()和 limit()选择正确的记录。分页要求将覆盖应用于查询的任何 limit()

Query pagination uses skip() and limit() internally to select the proper records. Any limit() applied to the query will be overwritten by the pagination requirements.

如果您愿意对结果的一个子集进行分页,您需要首先获取结果,然后为这些结果手动创建一个分页器。

If you'd like to paginate a subset of results, you will need to get the results first, and then manually create a paginator for those results.

这篇关于在分页功能中使用限制参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆