承接 camohub/paginator 相关项目开发

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

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

camohub/paginator

Composer 安装命令:

composer require camohub/paginator

包简介

Paginator for Laravel

README 文档

README

Laravel paginator for routes or route based pagination for Laravel :)

This package solves the problem with native Laravel paginator, which generates urls with query string parameters for the page.

https://example.com/category?page=4

This package allows you to create pretty urls with page parameter according route pattern.

https://example.com/category/4
# with fallback to
https://example.com/category?page=4

Installation

composer install camohub/paginator

Examples

Lets imagine a controller for articles with route

Route::get('/{categorySlug}/{page?}', 'ArticleController@index')->name('articles');

The index action displays all articles in required category.

public function index(Request $request, $categorySlug, $page = 1)
{
    $category = Category::where('slug', $categorySlug)->first()
    
    if( ! $category ) abort(404);
    
    $paginator = new Paginator($request, $category->articles(), 'articles', ['categorySlug' => $categorySlug]);

    $view = [
        'articles' => $paginator->getItems(),
        'paginator' => $paginator,
        'category' => $category,
    ];

    return view('articles.index', $view);
}

Paginator __construct() method expects second parameter to be query builder which can call skip() and take() methods to paginate the collection.

Internal implementation looks like

$this->items = $this->model->skip($this->skip)->take($this->perPage)->get();

and the view will look like

@foreach( $articles as $a ) 
... 
@endforeach 

{{$paginator->render()}}

Options

Paginator requires 3 non optional parameters.

  1. Request object
  2. Query builder / model
  3. Route name

In addition there are few optional parameters which can be used to configure the paginator.

  1. Route parameters - route paremeters without page parameter. Page param will be merged in template. Default is [].
  2. pageParam - the name of the route parameter which represents the page. Default is "page". Packege will look for $request->route()->parameter($pageParam) or $request->query($pageParam)
  3. perPage - items per page. Default is 15.
  4. sideItemsCount - the number of items around the current page in paginator. It is ekvivalent of Laravel native ->onEachSide() paginator method. Default is 3.

You can override the whole paginator with simple MyPaginator extends Paginator and also publish the template files and rewrites it. Current template is based on Bootstrap 4.

##Simple paginator There is also SimplePaginator class to create simple prev next navigation.

$paginator = new Paginator($request, $category->articles(), 'articles', ['categorySlug' => $categorySlug]);

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: mit
  • 更新时间: 2021-07-08

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固