php - Laravel paginate(10) 不适用于第二页
问题描述
我正在尝试 Laravel 的分页功能,但下面的 URL 每次都返回相同的记录。这意味着无论我们在哪个页面上,它都只显示前 10 条记录。我不知道为什么。
网址 - https://example.com/api/getWebGalleryImages?page=3
我的控制器功能
public function getWebGalleryImages() {
$galleryFIle = WebGallery::orderBy('id', 'desc')->paginate(10);
return response()->json($galleryFIle, 200);
}
我的路线
Route::get('getWebGalleryImages', 'FrontController@getWebGalleryImages');
每次都是一样的反应
{
"current_page": 1,
"data": [
{
"id": 11,
"file_name": "1627985668_download(2).jpg",
"created_at": null,
"updated_at": null
},
{
"id": 10,
"file_name": "1627985646_istockphoto-1093301674-612x612.jpg",
"created_at": null,
"updated_at": null
},
{
"id": 9,
"file_name": "1627985646_images(4).jpg",
"created_at": null,
"updated_at": null
},
{
"id": 8,
"file_name": "1627985646_images(3).jpg",
"created_at": null,
"updated_at": null
},
{
"id": 7,
"file_name": "1627985645_images(2).jpg",
"created_at": null,
"updated_at": null
},
{
"id": 6,
"file_name": "1627985645_images(1).jpg",
"created_at": null,
"updated_at": null
},
{
"id": 5,
"file_name": "1627985645_download(2).jpg",
"created_at": null,
"updated_at": null
},
{
"id": 4,
"file_name": "1627985645_download(1).jpg",
"created_at": null,
"updated_at": null
},
{
"id": 3,
"file_name": "1627985644_Diamond.jpg",
"created_at": null,
"updated_at": null
},
{
"id": 2,
"file_name": "1627985644_depositphotos_3929711-stock-photo-diamond-on-black-background.jpg",
"created_at": null,
"updated_at": null
}
],
"first_page_url": "https://example.com/api/getWebGalleryImages?page=1",
"from": 1,
"last_page": 2,
"last_page_url": "https://example.com/api/getWebGalleryImages?page=2",
"next_page_url": "https://example.com/api/getWebGalleryImages?page=2",
"path": "https://example.com/api/getWebGalleryImages",
"per_page": 10,
"prev_page_url": null,
"to": 10,
"total": 11
}
解决方案
从您的问题的响应中,您的查询似乎有11条匹配的记录,并且您的每页结果设置为10 ,这意味着您只有2页记录。因此,在您的查询中调用page=3
不会为您提供新记录,因为该页面不可用。
如果您需要分页工作,请将每页结果设置为较低的值,例如3或向记录中添加更多数据。
推荐阅读
- windows - Windows 中是否内置了安全的非对称密钥存储?
- c# - 检查字符串是否正好包含一个字符
- corda - 在 Corda 事务中,获取与特定状态关联的命令
- constructor - Ionic 3 - 在我再次“服务”之前看不到 json 文件的更改
- c++ - 使用 pcl 库的 Cmake 错误
- javascript - 17位时间戳的区别
- c++ - 无法解释以下 C++ 代码段的输出
- jenkins - Jenkins:从主服务器上的构建文件夹复制到从服务器上的工作区
- javascript - 对浏览器的同源策略感到困惑
- angular - 当 api 位于不同域时,如何通过 Angular Service Worker 缓存 Api 响应