定制 danbovey/laravel-linkheader-paginator 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

danbovey/laravel-linkheader-paginator

最新稳定版本:1.0.1

Composer 安装命令:

composer require danbovey/laravel-linkheader-paginator

包简介

Laravel Paginator that moves pagination info to the HTTP LinkHeader

README 文档

README

Travis Packagist Downloads Version License

A custom Laravel/Lumen Paginator that uses the Link header (RFC 5988) to send pagination info in the response. Removes the envelope around data!

Adds a method called toResponse that returns a JSON response with headers. The getHeaders method exists if you need different response data.

Installation

$ composer require danbovey/laravel-linkheader-paginator

Usage

Create the pagination with the Eloquent/DB Builder and pass it to the LengthAwarePaginator.

$items = User::where('active', 1)->paginate(20);

$paginator = new LengthAwarePaginator($items);

return $paginator->toResponse();

"Simple Pagination"

The simple paginator does not need to know the total number of items in the result set; however, because of this, the class does not return the URI of the last page. Ironically, the simple paginator is more work using this library. To save on queries you should skip using the methodsimplePaginate, and implement the skip/take logic yourself.

$page = $request->get('page');
$perPage = 20;
// Take one more than needed to see if there is a next page
$users = User::skip(($page - 1) * $perPage)
    ->take($perPage + 1);

$paginator = new Paginator($simple, $items);

return $paginator->toResponse();

统计信息

  • 总下载量: 3.91k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 3
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 3
  • Watchers: 1
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2016-11-06