publicoms/laravel-custom-paginator 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

publicoms/laravel-custom-paginator

Composer 安装命令:

composer require publicoms/laravel-custom-paginator

包简介

Paginate based on last item, not pages.

README 文档

README

Paginate based on last item, not page.

Build Status StyleCI Codacy Badge Codacy Badge

Installation

composer require publicoms/laravel-custom-paginator

Add the following trait to your Models.

use \publicoms\ItemPaginator\ItemPaginatorTrait;

Add the following provider to config/app.php

\publicoms\ItemPaginator\ItemPaginatorServiceProvider::class,

Usage

This package is based off simplePaginate and will take the same parameters.

$users = new User();

$paginated = $users->itemPaginate();

dd($paginated);

The last parameter is the field that will be used to paginate by, defaults to id.

itemPaginate($perPage = null, $columns = ['*'], $pageName = 'from', $from = 0, $field = null)

ORDER BY DESC

If you want to decend your sorting you'll want to use itemPaginateDesc instead of itemPaginate. The first page will add an extra query to find the last item.

Example Output

array:6 [
  "limit" => 2
  "next_page_url" => "http://localhost?from=190"
  "from" => 100
  "to" => 190
  "data" => array:2 [
    0 => array:8 [
      "id" => 100
      "name" => "test"
      "email" => "test@test.com"
      "password" => "test"
      "remember_token" => null
      "created_at" => "2016-08-02 18:13:19"
      "updated_at" => "2016-08-02 18:13:19"
      "deleted_at" => null
    ]
    1 => array:8 [
      "id" => 190
      "name" => "test2"
      "email" => "test2@test.com"
      "password" => "test"
      "remember_token" => null
      "created_at" => "2016-08-02 18:13:19"
      "updated_at" => "2016-08-02 18:13:19"
      "deleted_at" => null
    ]
  ]
]

Disclaimer

Will only sort by incremental ids.

I've only tested this with sqlite and mysql (see tests) so it may not work in every situation. Please report any you find.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-03-10