我有这样一行:
$users = User::where(something)->paginate(20);
如果现在我在第 2 页,如何获得数字 21 和 40?
最佳答案
您可以使用 ->firstItem()
和 ->lastItem()
方法来获取分页限制,Check for more details
$users = User::where(something)->paginate(20);
$from = $users->firstItem();//will give you 20(index of 21st item) on page 2
$to = $users->lastItem();//will give you 39(index of 40th item) on page 2
关于Laravel:如何获取当前页面的开始和结束记录号?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/49405959/