acadea/collection-paginator

Laravel 包用于分页任何集合

v1.0.1 2021-01-14 06:53 UTC

This package is auto-updated.

Last update: 2024-09-14 14:51:51 UTC


README

Latest Version on Packagist GitHub Tests Action Status Total Downloads

一个辅助包,用于分页 Laravel 集合。

关于

了解此包背后的理念

在 Youtube 上关注我们:Acadea.io

安装

您可以通过 composer 安装此包

composer require acadea/collection-paginator

用法

$collection = collect([1,2,3,4,5,6,7,8]);

$pageSize = 4;

$paginated = \Acadea\CollectionPaginator\CollectionPaginator::paginate($collection, $pageSize);

// ..

// in resource controller, returning as an api response
return new \Illuminate\Http\JsonResponse($paginated);

期望

{
    "current_page": 1,
    "data": [
        1,
        2,
        3,
        4
    ],
    "first_page_url": "https://:8000/api/fruits?page=1",
    "from": 1,
    "last_page": 2,
    "last_page_url": "https://:8000/api/fruits?page=2",
    "links": [
        {
            "url": null,
            "label": "Previous",
            "active": false
        },
        {
            "url": "https://:8000/api/fruits?page=1",
            "label": 1,
            "active": true
        },
        {
            "url": "https://:8000/api/fruits?page=2",
            "label": 2,
            "active": false
        },
        {
            "url": "https://:8000/api/fruits?page=2",
            "label": "Next",
            "active": false
        }
    ],
    "next_page_url": "https://:8000/api/fruits?page=2",
    "path": "https://:8000/api/fruits",
    "per_page": 4,
    "prev_page_url": null,
    "to": 4,
    "total": 8
}

测试

composer test

变更日志

请参阅 CHANGELOG 了解最近更改的详细信息。

贡献

请参阅 CONTRIBUTING 了解详细信息。

安全漏洞

请查阅 我们的安全策略 了解如何报告安全漏洞。

致谢

许可

MIT 许可证 (MIT)。请参阅 许可文件 了解更多信息。