2017 © Pedro Peláez
 

library pagination

Laravel 5 Custom Pagination Presenter

image

landish/pagination

Laravel 5 Custom Pagination Presenter

  • Wednesday, July 26, 2017
  • by Landish
  • Repository
  • 7 Watchers
  • 118 Stars
  • 45,981 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 24 Forks
  • 2 Open issues
  • 11 Versions
  • 6 % Grown

The README.md

Landish/Pagination

Note: Works with only 5.0, 5.1 and 5.2 versions. 5.3 and above it does not work. PR's welcome!, (*1)

Build Status Latest Stable Version Total Downloads Latest Unstable Version License, (*2)

Laravel 5 comes with Pagination class, which is perfectly rendered to match Bootstrap 3 styles., (*3)

This package gives you ability to change the display output of rendered pagination elements for Front-end Frameworks, such as: Semantic UI, Zurb Foundation, UIKit and Materialize., (*4)

With this package it is also very easy to create custom pagination HTML output., (*5)

Table of Contents

Installation

To install landish/pagination package, you have to run the following command in your Terminal, or Comand Promt:, (*6)

$ composer require landish/pagination

Or manually add the following lines in to your composer.json file:, (*7)

"require": {
    "landish/pagination": "~1.0"
}

and run the composer update or composer install command., (*8)

Usage

Add following lines of code in your *.blade.php file, where you want to dispay the pagination., (*9)

For Semantic UI:, (*10)

{!! (new Landish\Pagination\SemanticUI($items))->render() !!}
// or add "\Simple" in namespace for "Simple Pagination"
{!! (new Landish\Pagination\Simple\SemanticUI($items))->render() !!}

For Zurb Foundation:, (*11)

{!! (new Landish\Pagination\ZurbFoundation($items))->render() !!}
// or add "\Simple" in namespace for "Simple Pagination"
{!! (new Landish\Pagination\Simple\ZurbFoundation($items))->render() !!}

For UIKit:, (*12)

{!! (new Landish\Pagination\UIKit($items))->render() !!}
// or add "\Simple" in namespace for "Simple Pagination"
{!! (new Landish\Pagination\Simple\UIKit($items))->render() !!}

For Materialize (Contributed by @arandilopez):, (*13)

{!! (new Landish\Pagination\Materialize($items))->render() !!}
// or add "\Simple" in namespace for "Simple Pagination"
{!! (new Landish\Pagination\Simple\Materialize($items))->render() !!}

If you display pagination on several pages of your web application and have to write to the output code in several files, then this is, what I would recommend to do:, (*14)

Just create Pagination.php file in your /app/ directory and paste the following code:, (*15)

Note: This example is suitable for you, if you haven't change the Laravel Application Namespace, otherwise just use your custom namespace instead of App., (*16)

<?php namespace App;

use Landish\Pagination\SemanticUI;

// Uncomment bellow line, if you like to use "Simple Pagination"
// use Landish\Pagination\Simple\SemanticUI;

class Pagination extends SemanticUI {

}

In that case, you only have to add the following code in your blade template files:, (*17)

{!! (new App\Pagination($items))->render() !!}

And in future, if you decide to override the output of pagination elements, it will be much more easier to change in app/Pagination.php file, rather then in several blade template files., (*18)

Simple Pagination

Laravel gives you ability to create "Simple Pagination", which will have only Previous and Next buttons, something like Bootstrap has., (*19)

The landish/pagination package supports this kind of pagination for Semantic UI, Zurb Foundation and UIKit., (*20)

In order to use, first call the simplePaginate() method on Eloquent Model., (*21)

$items = User::where('votes', '>', 100)->simplePaginate(15);

And after that, add the \Simple suffix in namespace, when displaying the pagination output. Something like this:, (*22)

{!! (new Landish\Pagination\Simple\ZurbFoundation($items))->render() !!}

Additional Wrappers

If you need to add additional wrappers to your pagination output, which will be displayed only if items have pages, then you can do it like this:, (*23)

@if($items->hasPages())
    <div class="pagination-wrapper">
        <div class="pagination-wrapper-inner">
            {!! (new App\Pagination($items))->render() !!}
        </div>
    </div>
@endif

Of course, you are free to change the .pagination-wrapper and .pagination-wrapper-inner CSS classes and the HTML., (*24)

Appending to pagination links gives you ability to add extra query strings to your pagination links., (*25)

With this package you can do it with following lines of code:, (*26)

{!! $items->appends(['key' => 'value'])->render(new App\Pagination($items))  !!}

Create Custom Pagination

Creating custom pagination or extending landish/pagination package is very easy., (*27)

Landish\Pagination\PaginationHTML class contains the following properties:, (*28)

<?php namespace Landish\Pagination;

class PaginationHTML {

    /**
     * Pagination wrapper HTML.
     *
     * @var string
     */
    protected $paginationWrapper = '<ul class="pagination">%s %s %s</ul>';

    /**
     * Available page wrapper HTML.
     *
     * @var string
     */
    protected $availablePageWrapper = '<li><a href="%s">%s</a></li>';

    /**
     * Get active page wrapper HTML.
     *
     * @var string
     */
    protected $activePageWrapper = '<li class="active"><span>%s</span></li>';

    /**
     * Get disabled page wrapper HTML.
     *
     * @var string
     */
    protected $disabledPageWrapper = '<li class="disabled"><span>%s</span></li>';

    /**
     * Previous button text.
     *
     * @var string
     */
    protected $previousButtonText = '&laquo;';

    /**
     * Next button text.
     *
     * @var string
     */
    protected $nextButtonText = '&raquo;';

    /***
     * "Dots" text.
     *
     * @var string
     */
    protected $dotsText = '...';

    ...

    }

Simply extend the Landish\Pagination\Pagination class in your app/Pagination.php file, just like I recommended above and overwrite these properties:, (*29)

<?php namespace App;

use Landish\Pagination\Pagination as BasePagination;

class Pagination extends BasePagination {

    /**
     * Pagination wrapper HTML.
     *
     * @var string
     */
    protected $paginationWrapper = '<ol class="pagination-extended-css-class">%s %s %s</ol>';

    ...
}

After that, just simply place the following code in your blade template file., (*30)

{!! (new App\Pagination($items))->render() !!}

License

The Landish/Pagination package is open-sourced software licensed under the MIT license, (*31)

The Versions

26/07 2017

dev-master

9999999-dev

Laravel 5 Custom Pagination Presenter

  Sources   Download

MIT

The Development Requires

by Lado Lomidze

laravel pagination

08/03 2017

1.3.3

1.3.3.0

Laravel 5 Custom Pagination Presenter

  Sources   Download

MIT

The Development Requires

by Lado Lomidze

laravel pagination

01/07 2015

1.3.2

1.3.2.0

Laravel 5 Custom Pagination Presenter

  Sources   Download

MIT

The Development Requires

by Lado Lomidze

laravel pagination

25/05 2015

1.3.1

1.3.1.0

Laravel 5 Custom Pagination Presenter

  Sources   Download

MIT

The Development Requires

by Lado Lomidze

laravel pagination

25/05 2015

1.3.0

1.3.0.0

Laravel 5 Custom Pagination Presenter

  Sources   Download

MIT

The Development Requires

by Lado Lomidze

laravel pagination

17/04 2015

1.1.2

1.1.2.0

Laravel 5 Custom Pagination Presenter

  Sources   Download

MIT

The Development Requires

by Lado Lomidze

laravel pagination

07/04 2015

1.1.1

1.1.1.0

Laravel 5 Custom Pagination Presenter

  Sources   Download

MIT

by Lado Lomidze

01/04 2015

1.1.0

1.1.0.0

Laravel 5 Custom Pagination Presenter

  Sources   Download

MIT

by Lado Lomidze

01/04 2015

1.0.4

1.0.4.0

Laravel 5 Custom Pagination Presenter

  Sources   Download

MIT

by Lado Lomidze

29/03 2015

1.0.3

1.0.3.0

Laravel 5 Custom Pagination Presenter

  Sources   Download

MIT

by Lado Lomidze

28/03 2015

1.0.2

1.0.2.0

Laravel 5 Custom Pagination Presenter

  Sources   Download

MIT

by Lado Lomidze