承接 amamarul/laravel-paginator 相关项目开发

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

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

amamarul/laravel-paginator

Composer 安装命令:

composer require amamarul/laravel-paginator

包简介

Laravel Paginator for Collections or Arrays

README 文档

README

Make the pagination for arrays or Collections

Installation

Composer require

$ composer require amamarul/laravel-paginator

Add Provider into config/app.php

Amamarul\Paginator\PaginatorServiceProvider::class,

Usage

In Controller

  • Array
use Amamarul\Paginator\Paginator;
use Illuminate\Http\Request;

public function index(Request $request)
{
    $currentPage  = isset($request['page']) ? (int) $request['page'] : 1;
    $perPage      = 1;
    $path         = $request->path();

    $items = array_map(function ($value) {
        return [
        'name' => 'User #' . $value,
        'url'  => '/user/' . $value,
        ];
        }, range(1,1000));

        $paginator = new Paginator($items);
        $paginator = $paginator->paginate($currentPage,$perPage, $path);

    return view('index')->with('paginator', $paginator);
}
  • Collection
use App\User;
use Amamarul\Paginator\Paginator;
use Illuminate\Http\Request;

public function index(Request $request)
{
    $currentPage  = isset($request['page']) ? (int) $request['page'] : 1;
    $perPage      = 1;
    $path         = $request->path();

    $items = User::with('profile')->get()->sortBy('profile.name');

    $paginator = new Paginator($items);
    $paginator = $paginator->paginate($currentPage,$perPage, $path);

    return view('index')->with('paginator', $paginator);
}

In Blade View (index.blade.php)

@foreach ($paginator->items() as $element)
    <a href="{!!$element['url']!!}"><h3>{!!$element['name']!!}</h3></a>
@endforeach

{!! $paginator->render() !!}

Customize Page Name

By default the url has page name http://127.0.0.1:8000/?page=3 If you´d like to change the page name yo must only add a fourth parameter with the name. Like this

use App\User;
use Amamarul\Paginator\Paginator;
use Illuminate\Http\Request;

public function index(Request $request)
{
    $currentPage  = isset($request[$pageName]) ? (int) $request[$pageName] : 1;
    $perPage      = 1;
    $path         = $request->path();
    $pageName     = 'custom-name';

    $items = User::with('profile')->get()->sortBy('profile.name');

    $paginator = new Paginator($items);
    $paginator = $paginator->paginate($currentPage,$perPage, $path, $pageName);

    return view('index')->with('paginator', $paginator);
}

Feel free to send improvements

Created by Maru Amallo-amamarul

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2017-03-15

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固