Requirements Introduction
Laravel default paging, to achieve very elegant, but sometimes encounter modify the default style, for example, I want the default <ul class="pagination">
changed to<ul class="pagination pagination-sm no-margin">
Solution entry point
Laravel own pagination links style \ Pagination render method BootstrapThreePresenter generated Illuminate \ made, we make a fuss can be realized on this method.
Creating rewriting the render method of class
Create a file: App / Presenters / PagiationPresenter
<?php
namespace App\Presenters;
use Illuminate\Support\HtmlString;
use Illuminate\Pagination\BootstrapThreePresenter;
class PagiationPresenter extends BootstrapThreePresenter
{
public function render()
{
if ($this->hasPages()) {
return new HtmlString(sprintf(
'<ul class="pagination pagination-sm no-margin">%s %s %s</ul>',
$this->getPreviousButton(),
$this->getLinks(),
$this->getNextButton()
));
}
return '';
}
}
Create a service provider PaginationServiceProvider
<?php
namespace App\Providers;
use App\Presenters\PagiationPresenter;
use Illuminate\Pagination\Paginator;
use Illuminate\Pagination\AbstractPaginator;
use Illuminate\Support\ServiceProvider;
class PaginationServiceProvider extends ServiceProvider
{
/**
* Bootstrap the application services.
*
* @return void
*/
public function boot()
{
//自定义分页
Paginator::presenter(function (AbstractPaginator $paginator) {
return new PagiationPresenter($paginator);
});
}
/**
* Register the application services.
*
* @return void
*/
public function register()
{
//
}
}
Add a service provider to config / app.php
'providers' => [
/*
* Laravel Framework Service Providers...
*/
...
App\Providers\PaginationServiceProvider::class,
],
Original link: http://blog.kesixin.xin/article/52