承接 sammyt/paginate-collection 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

sammyt/paginate-collection

最新稳定版本:v1.0.1

Composer 安装命令:

composer require sammyt/paginate-collection

包简介

Allows laravel users to paginate a collection via a global helper method. Currently laravel only allows for native query builder pagination.

README 文档

README

Description:

Allows laravel users to paginate a collection via a global helper method. Currently laravel only allows for native query builder pagination.

Usage:

As a simple inline example I created a fresh Laravel project using: laravel new MyProject

In MyProject:

  1. Set up an .env file which connects to a local database.
  2. Run the out-of-the-box migrations making sure the users table is created.
  3. Use tinker to create some test users in the users table or create them manually in your DB

To test you can call this method globally and pass in your collection. Other method parameters are optional. Accepted parameters include:

  1. $collection => Required
  2. $perPage => Default is 15 but also accepts an int
  3. $currentPage => Default is null but also accepts an int
  4. $options => Any additional options you wish to pass

Below is an example use case of how to use the paginate_collection global helper method.

Follow steps 1-3 above and then create a route in web.php which has a callback function which will allow you to return a collection for testing

Route::get('/users', function() {
   $userCollection = User::all();

   $paginatedUsersCollection = paginate_collection(
       $userCollection,
       10,
       null
   );
   
   dd($paginatedUsersCollection);
});

Output

Illuminate\Pagination\LengthAwarePaginator {#251 ▼
  #total: 2
  #lastPage: 1
  #items: Illuminate\Support\Collection {#265 ▶}
  #perPage: 10
  #currentPage: 1
  #path: "/"
  #query: []
  #fragment: null
  #pageName: "page"
  +onEachSide: 3
  #options: []
}

As you can see it uses the LengthAwarePaginator behind the scenes and your collection is now paginated.

统计信息

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

GitHub 信息

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

其他信息

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

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固