dvsouto/laravel-json-paginate
Composer 安装命令:
composer require dvsouto/laravel-json-paginate
包简介
Create json paginate for API in Laravel/Lumen
关键字:
README 文档
README
In a vanilla Laravel application exists the method paginate in Query Builder (https://laravel.com/docs/7.x/pagination#paginating-eloquent-results), that returns the results formated to front pagination.
This package adds a jsonPaginate method to the Eloquent query builder that listens the results in json format to use in API and show data in others applications.
Installation
You can install the package via composer:
composer require dvsouto/laravel-json-paginate
In Laravel 5.5 and above the service provider will automatically get registered. In older versions of the framework just add the service provider in config/app.php file:
'providers' => [ ... Bitnary\JsonPaginate\JsonPaginateServiceProvider::class, // Bitnary JsonPaginate for o Eloquent ];
In Lumen you need to load de service provider on bootstrap/app.php file:
... $app->register(Bitnary\JsonPaginate\JsonPaginateServiceProvider::class); // Bitnary JsonPaginate for o Eloquent
Usage
To paginate the results prepared to return from API, simply call the jsonPaginate method.
YourModel::jsonPaginate();
Of course you may still use all the builder methods you know:
YourModel::where('my_field', 'myValue')->jsonPaginate();
By default the maximum page size is set to 100. You can change this number passing the value to jsonPaginate.
You also pass the each side parameter to method for generate the page keys.
$per_page = 10; // 10 Results per page $each_side = 3; // 3 buttons on each side YourModel::jsonPaginate($per_page, $each_side);
By default the maximum page size is set to 100. You can change this number passing the value to jsonPaginate.
$maxResults = 10; YourModel::jsonPaginate($maxResults);
This return an array containing thats parameters:
{
"data": [ // (object) Results for this page
{
"id": 1,
"name": "Davi Souto"
},
{
"id": 2,
"name": "Lorem Ipsum"
},
{
"id": 3,
"name": "Sit Amet"
},
...
],
"paginator": {
"current_page": 1, // (int) Current page number
"prev_page": 1, // (int) Previous page number
"next_page": 2, // (int) Next page number
"first_page": 1, // (int) The first page (always 1),
"is_first_page": true, // (boolean) Is in first page ?
"last_page": 25, // (int) Last page number
"is_last_page": false, // (boolean) Is in last page ?
"page_keys": [ // (array) Contains the list of pages to display in front
1,
2,
3,
4,
],
"from_item": 1, // (int) Results for this page starts from this item
"to_item": 100, // (int) Results for this page ends in this item
"total_items": 100, // (int) Total of existent itens
"per_page": 10, // (int) Results for this page ends in this item
"display_items": // (int) Total of itens in this page
}
}
Security
If you discover any security related issues, please email davi.souto@gmail.com instead of using the issue tracker.
Credits
License
The MIT License (MIT). Please see License File for more information.
dvsouto/laravel-json-paginate 适用场景与选型建议
dvsouto/laravel-json-paginate 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.24k 次下载、GitHub Stars 达 2, 最近一次更新时间为 2019 年 07 月 18 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「dvsouto」 「laravel-json-paginate」 「bitnary」 「lumen-json-paginate」 「laravel-api-json-paginate」 「lumen-api-json-paginate」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 dvsouto/laravel-json-paginate 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 dvsouto/laravel-json-paginate 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 1.24k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 2
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2019-07-18