如何通过分页返回API中资源的项目号?
用于项目表的编号,因此,如果第1页有5项,则第2页中的数字将从6开始到10开始。
我像往常一样使用paginate()函数
我的JSON现在是这样的:
{
"data": {
"current_page": 1,
"data": [
{
"id": 1,
"foto": null,
"nik": "292680381382302",
"nama": "Admin",
}
],
"first_page_url": "http://pmo-9.test/api/karyawan?page=1",
"from": 1,
"last_page": 1,
"last_page_url": "http://pmo-9.test/api/karyawan?page=1",
"links": [
{
"url": null,
"label": "« Previous",
"active": false
},
{
"url": "http://pmo-9.test/api/karyawan?page=1",
"label": "1",
"active": true
},
{
"url": null,
"label": "Next »",
"active": false
}
],
"next_page_url": null,
"path": "http://pmo-9.test/api/karyawan",
"per_page": "5",
"prev_page_url": null,
"to": 1,
"total": 1
}
}如何将number: 1列添加到响应中?
发布于 2022-03-09 02:30:10
我为我的问题找到了解决办法
$collection->each(function ($collect, $index) use ($collection) {
$collect->nomor = $collection->perPage() * ($collection->currentPage() - 1) + $index + 1;
});因为$collection是Model::paginate();。
就这样
发布于 2022-03-01 05:27:39
您的数据长度将给您此号码。如果您正在使用JS,那么只需使用data.length来实现它。
https://stackoverflow.com/questions/71303953
复制相似问题