creativecrafts/laravel-paginate-collection

一个方便的Laravel集合分页包

1.0.0 2024-03-17 18:21 UTC

README

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

这是一个方便的分页集合的包。

安装

您可以通过composer安装此包

composer require creativecrafts/laravel-paginate-collection

您可以使用以下命令发布配置文件

php artisan vendor:publish --tag="paginate-collection-config"

这是发布配置文件的内容

return [
   /**
     * This is the default number of items that will be displayed per page.
     * default: 10
     */
    'items_per_page' => 10,

    /**
     * This is the default page name that will be used in the query string.
     * default: page
     */
    'page_name' => 'page',
];

使用方法

You can use the Facade to paginate a collection
use CreativeCrafts\Paginate\Facades\Paginate 
or use the helper function
use CreativeCrafts\Paginate\Paginate;

$collection = collect([
   ['name' => 'Jack', 'age' => 40],
   ['name' => 'John', 'age' => 30],
   ['name' => 'Jane', 'age' => 25],
]);

$paginatedCollection = Paginate::collection($collection, 1);
// output:
// [
//    "current_page" => 1
//    "data" => [
//       0 => [
//          "name" => "Jack"
//          "age" => 40
//       ]
//    ],
//    "first_page_url" => "https://:8000/?page=1"
//    "from" => 1
//    "last_page" => 3
//    "last_page_url" => "https://:8000/?page=3"
//    "next_page_url" => "https://:8000/?page=2"
//    "path" => "https://:8000"
//    "per_page" => 1
//    "prev_page_url" => null
//    "to" => 1
//    "total" => 3
//    "links" => [
//       0 => [
//          "url" => "null",
//          "label" => "« Previous",
//          "active" => false
//       ],
//       1 => [
//          "url" => "https://:8000/?page=1",
//          "label" => "1",
//          "active" => true
//       ],
//       2 => [
//          "url" => "https://:8000/?page=2",
//          "label" => "2",
//          "active" => false
//       ],
//       3 => [
//          "url" => "https://:8000/?page=3",
//          "label" => "3",
//          "active" => false
//       ],
//       4 => [
//          "url" => "https://:8000/?page=2",
//          "label" => "Next »",
//          "active" => false
//       ]
//    ]
//]
You can get the default items per page from the config file
$paginatedCollection = Paginate::collection($collection, Paginate::defaultItemsPerPage());

You can also get the default page name that will be used in the query string from the config file
$pageName = Paginate::defaultPageName();

测试

composer test

变更日志

请参阅变更日志以获取有关最近更改的更多信息。

贡献

请参阅贡献指南以获取详细信息。

安全漏洞

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

鸣谢

许可证

MIT许可证(MIT)。请参阅许可证文件以获取更多信息。