定制 flagstudio/laravel-paginate 二次开发

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

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

flagstudio/laravel-paginate

最新稳定版本:v0.1.3

Composer 安装命令:

composer require flagstudio/laravel-paginate

包简介

Different paginate macros for laravel eloquent builder and collection

README 文档

README

Installation

You can pull in the package via composer:

composer require flagstudio/laravel-paginate

The package will automatically register itself.

Macros

These macros are used for Eloquent Builder and Collection. The main difference in using pagination on a collection or builder is that builder has not yet perform the database request, i.e. paginate will perform request to get needed amount of records from database. Collection already have all elements and paginate will not perform any database requests.

paginate

Create a LengthAwarePaginator instance from Builder or Collection.

collect($posts)->paginate(5); // From Collection instance
Post::orderBy('created_at', 'desc')->get()->paginate(5); // From Collection instance
Post::orderBy('created_at', 'desc')->paginate(5); // From Builder instance

This paginates the contents of $posts with 5 items per page. paginate accept some options, head over to the Laravel docs for an in-depth guide.

paginateFirstDifferent

Create a FirstDifferentLengthAwarePaginator.php instance which extend LengthAwarePaginator from Builder or Collection.

collect($posts)->paginateFirstDifferent(10, 5); // From Collection instance
Post::orderBy('created_at', 'desc')->get()->paginateFirstDifferent(10, 5); // From Collection instance
Post::orderBy('created_at', 'desc')->paginateFirstDifferent(10, 5); // From Builder instance

This paginates the contents of $posts with 10 items at first page and 5 items for next pages. paginateFirstDifferent accepts same options as paginate but instead of $perPage accepts two parameters $firstPerPage and $nextPerPage

You can also pass third parameter to get all post from first to current page.

Post::orderBy('created_at', 'desc')->paginateFirstDifferent(10, 5, true);

paginateWithPrevious

Create a LengthAwarePaginator instance from Builder or Collection.

collect($posts)->paginateWithPrevious(5); // From Collection instance
Post::orderBy('created_at', 'desc')->get()->paginateWithPrevious(5); // From Builder instance
Post::orderBy('created_at', 'desc')->paginateWithPrevious(5); // From Builder instance

This paginates the contents of $posts with 5 items per page but takes all posts from first to current page. At example if current page equals 5 then paginateWithPrevious will return 25 posts (5 per each page). It useful if you want load all posts for current page after reloading page or share link with pagination (https://website.com/posts?page=5). paginateWithPrevious accepts same options as paginate

统计信息

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

GitHub 信息

  • Stars: 15
  • Watchers: 2
  • Forks: 2
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-04-24

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固