Skip to content

Instantly share code, notes, and snippets.

@edomaru
Last active May 30, 2016 09:58
Show Gist options
  • Save edomaru/2094bc50b5da4628e7e56d7cb60129d1 to your computer and use it in GitHub Desktop.
Save edomaru/2094bc50b5da4628e7e56d7cb60129d1 to your computer and use it in GitHub Desktop.

Custom Laravel pagination style

  • create new file for example CustomPaginationPresenter.php below app directory
  • Extends the class from SimpleBootstrapThreePresenter like so:
<?php
namespace App;

use Illuminate\Support\HtmlString;
use Illuminate\Pagination\SimpleBootstrapThreePresenter;

class CustomPaginationPresenter extends SimpleBootstrapThreePresenter 
{
	/**
     * Convert the URL window into Bootstrap HTML.
     *
     * @return \Illuminate\Support\HtmlString
     */
    public function render()
    {
        if ($this->hasPages()) {
            return new HtmlString(sprintf(
                '<ul class="my-custom-pagination-class">%s %s %s</ul>',
                $this->getPreviousButton(),
                $this->getLinks(),
                $this->getNextButton()
            ));
        }

        return '';
    }
}
  • In the view file we can call like so:
{!! $contacts->appends( Request::query() )->render( new \App\CustomPaginationPresenter($contacts) ) !!}
  • That's it. For customing other pagination style you can copy the code from SimpleBootstrapThreePresenterand redefine/ override in your own class with your style.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment