creativecrafts / laravel-paginate-collection
一个方便的Laravel集合分页包
1.0.0
2024-03-17 18:21 UTC
Requires
- php: ^8.2
- illuminate/contracts: ^11.0|^10.0
- spatie/laravel-package-tools: ^1.16
Requires (Dev)
- larastan/larastan: ^2.9
- laravel/pint: ^1.14
- nunomaduro/collision: ^8.1|^7.0
- orchestra/testbench: ^9.0|^8.0
- pestphp/pest: ^2.34
- pestphp/pest-plugin-arch: ^2.7
- pestphp/pest-plugin-laravel: ^2.3
- phpstan/extension-installer: ^1.3
- phpstan/phpstan-deprecation-rules: ^1.1
- phpstan/phpstan-phpunit: ^1.3
This package is auto-updated.
Last update: 2024-09-08 18:49:48 UTC
README
这是一个方便的分页集合的包。
安装
您可以通过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)。请参阅许可证文件以获取更多信息。