chelout/offset-pagination
Composer 安装命令:
composer require chelout/offset-pagination
包简介
Offset pagination made easy for Laravel
关键字:
README 文档
README
This package provides an offset based pagination already integrated with Laravel's query builder and Eloquent ORM. It calculates the SQL query limits automatically by checking the requests GET parameters, and automatically builds the next and previous urls for you.
Installation
You can install this package via composer using:
composer require chelout/offset-pagination
The package will automatically register itself.
Config
To publish the config file to config/offset_pagination.php run:
php artisan vendor:publish --provider="Chelout\OffsetPagination\CursorPaginationServiceProvider" --tag="config"
This will publish the following file. You can customize default items per page and maximum items per page.
Basic Usage
Paginating Query Builder Results
public function index() { $users = DB::table('users')->offsetPaginate(); return $users; }
Paginating Eloquent Results
$users = User::offsetPaginate(5);
Of course, you may call paginate after setting other constraints on the query, such as where clauses:
$users = User::where('votes', '>', 100)->offsetPaginate(5);
Or sorting your results:
$users = User::orderBy('id', 'desc')->offsetPaginate(5);
Displaying Pagination Results
Converting to JSON
A basic return will transform the paginator to JSON and will have a result like this:
Route::get('api/v1/users', function () { return App\User::offsetPaginate(); });
Calling api/v1 will output:
{
"data": [
{},
],
"offset": 60,
"offset": 60,
"prev": 55,
"next": 65,
"limit": 5,
"total": 100,
"next_page_url": "https://example.com/api/v1/users?limit=5&offset=65",
"prev_page_url": "https://example.com/api/v1/users?limit=5&offset=55"
}
Using a Resource Collection
By default, Laravel's API Resources when using them as collections, they will output a paginator's metadata
into links and meta.
{
"data":[
{},
],
"links": {
"first": "https://example.com/api/v1/users",
"last": "https://example.com/api/v1/users?offset=95",
"prev": "https://example.com/api/v1/users?offset=55",
"next": "https://example.com/api/v1/users?offset=65"
},
"meta": {
"offset": 60,
"prev": 55,
"next": 65,
"limit": 5,
"total": 100
},
}
Testing
Run the tests with:
vendor/bin/phpunit
Credits
- Viacheslav Ostrovskiy
- All Contributors
License
The MIT License (MIT). Please see License File for more information.
chelout/offset-pagination 适用场景与选型建议
chelout/offset-pagination 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 4.96k 次下载、GitHub Stars 达 4, 最近一次更新时间为 2018 年 03 月 12 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「api」 「pagination」 「laravel」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 chelout/offset-pagination 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 chelout/offset-pagination 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 chelout/offset-pagination 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A PSR-7 compatible library for making CRUD API endpoints
Provides a Data Grid tables for your Symfony project.
Normalize an index range from user input
Display page number links in Twig or PHP templates.
Alfabank REST API integration
Symfony package for pagination, sorting and filtering of a list items.
统计信息
- 总下载量: 4.96k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 4
- 点击次数: 10
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2018-03-12