apichef/laravel-request-query-helper
Composer 安装命令:
composer require apichef/laravel-request-query-helper
包简介
Easily interact with JSON-API query params.
README 文档
README
Easily interact with JSON-API query params.
Install
Via Composer
$ composer require apichef/laravel-request-query-helper
You can publish the config file with:
$ php artisan vendor:publish --provider="ApiChef\RequestQueryHelper\RequestQueryHelperServiceProvider"
Usage
Configuration
Default configuration is follows the {json:api} specification.
return [ /* Configuration for inclusion of related resources */ 'include' => [ 'name' => 'include', ], /* Configuration for filtering resource collections */ 'filter' => [ 'name' => 'filter', ], /* Configuration for sorting resource collections */ 'sort' => [ 'name' => 'sort', ], /* Configuration for sparse field-sets */ 'fields' => [ 'name' => 'fields', ], /* Configuration for pagination */ 'pagination' => [ 'name' => 'page', 'number' => 'number', 'size' => 'size', ], ];
Includes and Filters
This package adds filters and includes methods to the query object. Both methods returns QueryParamBag, which is capable of parsing array-based and string-based request query strings.
Eg:
GET '/posts?include=comments:limit(5):sort(created_at|desc),author'
or
GET '/posts?include[comments][limit]=5&include[comments][sort]=created_at|desc&include[author]'
Following examples are based on above request.
use Illuminate\Http\Request; class ExampleController extends Controller { public function show(Request $request) { $params = $request->includes(); // has $params->has('comments'); // true $params->has('comments.limit'); // true $params->has('comments.sort'); // true $params->has('comments.foo'); // false $params->has('author'); // true // get $params->get('comments.limit'); // [5] $params->get('comments.sort'); // ['created_at', 'desc'] // isEmpty $params->isEmpty('comments'); // false $params->isEmpty('author'); // true } } ## Sorts // todo ## Fields // todo ## Pagination // todo
Change log
Please see CHANGELOG for more information on what has changed recently.
Testing
$ composer test
Contributing
Please see CONTRIBUTING and CODE_OF_CONDUCT for details.
Security
If you discover any security related issues, please email milroy@outlook.com instead of using the issue tracker.
Credits
License
The MIT License (MIT). Please see License File for more information.
统计信息
- 总下载量: 223
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 4
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2020-02-12