1、自定義一個類(代碼以下),位置隨你放,注意命名空間。
2、模板輸出調用 {!! $data->render(new \App\Http\Controllers\ShmilyThreePresenter($data)) !!}
最終樣式php
_html
<?php //建立繼承自 Illuminate\Pagination\BootstrapThreePresenter 類,這裏我把類放在了Controllers下面,須要修改BootstrapThreePresenter 類的哪些方法就重寫哪一個方法。若是以爲默認的bootstrap樣式和你項目的樣式不符,能夠自定義樣式。 namespace App\Http\Controllers; use Illuminate\Contracts\Pagination\Paginator as PaginatorContract; use Illuminate\Contracts\Pagination\Presenter as PresenterContract; class ShmilyThreePresenter extends \Illuminate\Pagination\BootstrapThreePresenter { /** * Convert the URL window into Bootstrap HTML. * * @return string */ public function render() { if ($this->hasPages()) { return sprintf( '<ul class="am-pagination">%s %s %s %s %s</ul>',//自定義class樣式 $this->firstPage(),//添加首頁方法 $this->getPreviousButton('上一頁'), $this->getLinks(), $this->getNextButton('下一頁'), $this->last()//添加尾頁方法 ); } return ''; } /** * Get HTML wrapper for an available page link. * * @param string $url * @param int $page * @param string|null $rel * @return string */ protected function getAvailablePageWrapper($url, $page, $rel = null) { $rel = is_null($rel) ? '' : ' rel="'.$rel.'"'; return '<li><a href="'.htmlentities($url).'"'.$rel.'>'.$page.'</a></li>'; //這裏li標籤能夠添加你本身的class樣式 } /** * Get HTML wrapper for disabled text. * * @param string $text * @return string */ protected function getDisabledTextWrapper($text) { return '<li class="disabled"><span>'.$text.'</span></li>'; } /** * Get HTML wrapper for active text. * * @param string $text * @return string */ protected function getActivePageWrapper($text) { return '<li class="active"><span>'.$text.'</span></li>'; } /** * Get the next page pagination element. * * @param string $text * @return string */ //新建首頁方法 public function firstPage($text = '首頁') { // If the current page is greater than or equal to the last page, it means we // can't go any further into the pages, as we're already on this last page // that is available, so we will make it the "next" link style disabled. if ($this->paginator->currentPage() <= 1) { return $this->getDisabledTextWrapper($text); } $url = $this->paginator->url(1); return $this->getPageLinkWrapper($url, $text, 'first'); } /** * Get the next page pagination element. * * @param string $text * @return string */ //新建尾頁方法 public function last($text = '尾頁') { // If the current page is greater than or equal to the last page, it means we // can't go any further into the pages, as we're already on this last page // that is available, so we will make it the "next" link style disabled. $url = $this->paginator->url($this->paginator->lastPage()); return $this->getPageLinkWrapper($url, $text, 'last'); } }