douzhouhan4618 2019-06-26 08:56
浏览 180

如何在没有键Laravel的情况下对集合进行分页

I have an array of values with keys (like 0,1,2 etc). I need to paginate it and at result take collection of those values without keys.

At start I have array like this

array:11 [
  0 => {#829
    +"id": 2417
    +"date": "2019-12-24 15:05:04"
    +"eventName": "Atlas"
    +"gift_type": null
    +"count": 2
  }
  1 => {#872
    +"id": 2409
    +"date": "2019-08-22 19:00:00"
    +"eventName": "ДАХАБРАХА. ЗЕМЛЯ"
    +"gift_type": "to"
    +"count": 4
  }
]

And after pagination I need to get this, and I get it at first page :

{
    "current_page": 1,
    "data": [
        {
            "id": 2417,
            "date": "2019-12-24 15:05:04",
            "eventName": "Atlas",
            "gift_type": null,
            "count": 2
        },
        {
            "id": 2409,
            "date": "2019-08-22 19:00:00",
            "eventName": "ДАХАБРАХА. ЗЕМЛЯ",
            "gift_type": "to",
            "count": 4
        }
    ],
    "first_page_url": "http://ticketsale/ajax/orders/77?page=1",
    "from": 1,
    "last_page": 4,
    "last_page_url": "http://ticketsale/ajax/orders/77?page=4",
    "next_page_url": "http://ticketsale/ajax/orders/77?page=2",
    "path": "http://ticketsale/ajax/orders/77",
    "per_page": 3,
    "prev_page_url": null,
    "to": 3,
    "total": 11
}

But at second page I take values WITH keys:

{
    "current_page": 2,
    "data": {
        "3": {
            "id": 2404,
            "date": "2019-08-22 19:00:00",
            "eventName": "ДАХАБРАХА. ЗЕМЛЯ",
            "gift_type": "to",
            "count": 3
        },
        "4": {
            "id": 2400,
            "date": "2019-08-22 19:00:00",
            "eventName": "ДАХАБРАХА. ЗЕМЛЯ",
            "gift_type": "to",
            "count": 1
        }
    },
    "first_page_url": "http://ticketsale/ajax/orders/77?page=1",
    "from": 4,
    "last_page": 4,
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥100 Jenkins自动化部署—悬赏100元
    • ¥15 关于#python#的问题:求帮写python代码
    • ¥20 MATLAB画图图形出现上下震荡的线条
    • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
    • ¥15 perl MISA分析p3_in脚本出错
    • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
    • ¥15 ubuntu虚拟机打包apk错误
    • ¥199 rust编程架构设计的方案 有偿
    • ¥15 回答4f系统的像差计算
    • ¥15 java如何提取出pdf里的文字?