在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):spatie/laravel-json-api-paginate开源软件地址(OpenSource Url):https://github.com/spatie/laravel-json-api-paginate开源编程语言(OpenSource Language):PHP 100.0%开源软件介绍(OpenSource Introduction):A paginator that plays nice with the JSON API specIn a vanilla Laravel application the query builder paginators will listen to This package adds a Support usWe invest a lot of resources into creating best in class open source packages. You can support us by buying one of our paid products. We highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You'll find our address on our contact page. We publish all received postcards on our virtual postcard wall. InstallationYou can install the package via composer: composer require spatie/laravel-json-api-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 'providers' => [
...
Spatie\JsonApiPaginate\JsonApiPaginateServiceProvider::class,
]; Optionally you can publish the config file with: php artisan vendor:publish --provider="Spatie\JsonApiPaginate\JsonApiPaginateServiceProvider" --tag="config" This is the content of the file that will be published in <?php
return [
/*
* The maximum number of results that will be returned
* when using the JSON API paginator.
*/
'max_results' => 30,
/*
* The default number of results that will be returned
* when using the JSON API paginator.
*/
'default_size' => 30,
/*
* The key of the page[x] query string parameter for page number.
*/
'number_parameter' => 'number',
/*
* The key of the page[x] query string parameter for page size.
*/
'size_parameter' => 'size',
/*
* The key of the page[x] query string parameter for cursor.
*/
'cursor_parameter' => 'cursor',
/*
* The name of the macro that is added to the Eloquent query builder.
*/
'method_name' => 'jsonPaginate',
/*
* If you only need to display Next and Previous links, you may use
* simple pagination to perform a more efficient query.
*/
'use_simple_pagination' => false,
/*
* If you want to cursor pagination, set this to true.
* This would override use_simple_pagination.
*/
'use_cursor_pagination' => false,
/*
* Here you can override the base url to be used in the link items.
*/
'base_url' => null,
/*
* The name of the query parameter used for pagination
*/
'pagination_parameter' => 'page',
]; UsageTo paginate the results according to the json API spec, simply call the YourModel::jsonPaginate(); Of course you may still use all the builder methods you know and love: YourModel::where('my_field', 'myValue')->jsonPaginate(); By default the maximum page size is set to 30. You can change this number in the $maxResults = 60;
YourModel::jsonPaginate($maxResults); Cursor paginationThis package also supports cursor pagination, which can be briefly defined by the Laravel Framework as follows:
You can find more about cursor pagination in the Laravel Documentation. If you want to use cursor pagination, you can set the It's also possible to modify the pagination parameter in the <?php
return [
// ..... other config options .....
/*
* The key of the page[x] query string parameter for cursor.
*/
'cursor_parameter' => 'cursor',
/*
* If you want to cursor pagination, set this to true.
* This would override use_simple_pagination.
*/
'use_cursor_pagination' => true,
// ..... other config options .....
]; ChangelogPlease see CHANGELOG for more information what has changed recently. Testingcomposer test ContributingPlease see CONTRIBUTING for details. SecurityIf you've found a bug regarding security please mail [email protected] instead of using the issue tracker. CreditsThe base code of this page was published on this Laracasts forum thread by Joram van den Boezem LicenseThe MIT License (MIT). Please see License File for more information. |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论