ryanwinchester/laravel-paginates
Composer 安装命令:
composer require ryanwinchester/laravel-paginates
包简介
Laravel controller trait for paginating models
README 文档
README
This trait adds a super duper handy method that will give you behaviour from requests slightly similar to what something like league/fractal gives you without all the setup and needing to create transformers.
Between this trait, and Eloquent Models' $casts and $hidden properties, starting a basic API with about as much control as some more heavyweight packages give you, will be really quick.
Install
composer require ryanwinchester/laravel-paginates
Usage
Add it to your controller (or base controller, as shown):
// ... use RyanWinchester\Paginates\PaginatesModels; class Controller extends BaseController { use AuthorizesRequests, DispatchesJobs, ValidatesRequests, PaginatesModels; }
Then use it in your controller methods like so:
class ProductsController extends Controller { public function index() { $products = $this->paginate(Product::class); return response()->json($products); } }
Sometimes because of security or privacy, you may want to limit include relationships and/or columns.
If that is the case, then be sure to include the parameters you want, making sure to exclude any user-supplied include parameters.
$products = $this->paginate( Product::class, $request->except(['include', 'columns']) );
Or, say you want to define some included relationships yourself:
$products = $this->paginate( Product::with('variations'), $request->except(['include', 'columns']) );
Or, even limit to specific columns:
$products = $this->paginate( Product::select(['id', 'price', 'in_stock']), $request->except('columns') );
You can pass in any builder instance or a model class name.
Parameters:
- page :
page=3the page number - perPage :
perPage=10amount to show per page - columns :
columns=title,body,authorlimit to certain columns - include :
include=categories,tagsload relations - orderBy :
orderBy=published|descorder the items by a column and direction
In action
Then you can go to your route and add some of these optional parameters to page and filter:
Please try it out and give feedback.
Taylor thinks it's a good idea, so I mean what other reason do you need?
ryanwinchester/laravel-paginates 适用场景与选型建议
ryanwinchester/laravel-paginates 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 47 次下载、GitHub Stars 达 2, 最近一次更新时间为 2017 年 10 月 09 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 ryanwinchester/laravel-paginates 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 ryanwinchester/laravel-paginates 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 47
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 6
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: Apache-2.0
- 更新时间: 2017-10-09