laravel默认了分页,实现很是优雅,但有时候会遇到修改默认的样式,好比我要将默认的<ul class="pagination">
修改成<ul class="pagination pagination-sm no-margin">
php
Laravel自带的分页连接样式由IlluminatePaginationBootstrapThreePresenter的render方法生成,咱们在此方法上作文章便可实现。laravel
建立文件:App/Presenters/PagiationPresentergit
<?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 ''; } }
<?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() { // } }
'providers' => [ /* * Laravel Framework Service Providers... */ ... App\Providers\PaginationServiceProvider::class, ],
QQ : 339803849 (欢迎加入)github
个人开源博客Moell Blogapp