Created
August 13, 2016 19:40
-
-
Save pinguinjkeke/748ca6c807a2b4cb0380f61b83745b8f to your computer and use it in GitHub Desktop.
Laravel MaterializeCss pagination presenter
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Pagination; | |
use Illuminate\Pagination\BootstrapThreePresenter; | |
use Illuminate\Support\HtmlString; | |
class MaterializeCssPresenter extends BootstrapThreePresenter | |
{ | |
/** | |
* Convert the URL window into Bootstrap HTML. | |
* | |
* @return \Illuminate\Support\HtmlString | |
*/ | |
public function render() | |
{ | |
if ($this->hasPages()) { | |
return new HtmlString(sprintf( | |
'<ul class="pagination">%s %s %s</ul>', | |
$this->getPreviousButton('<i class="fa fa-angle-left"></i>'), | |
$this->getLinks(), | |
$this->getNextButton('<i class="fa fa-angle-right"></i>') | |
)); | |
} | |
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 = ($rel === null) ? '' : ' rel="'.$rel.'"'; | |
return '<li class="waves-effect"><a href="'.htmlentities($url).'"'.$rel.'>'.$page.'</a></li>'; | |
} | |
/** | |
* Get HTML wrapper for disabled text. | |
* | |
* @param string $text | |
* @return string | |
*/ | |
protected function getDisabledTextWrapper($text) | |
{ | |
return '<li class="disabled"><a href="javascript:void(0)">'.$text.'</a></li>'; | |
} | |
/** | |
* Get HTML wrapper for active text. | |
* | |
* @param string $text | |
* @return string | |
*/ | |
protected function getActivePageWrapper($text) | |
{ | |
return '<li class="active"><a href="javascript:void(0)">'.$text.'</a></li>'; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Providers; | |
use App\Pagination\MaterializeCssPresenter; | |
use Illuminate\Pagination\Paginator; | |
use Illuminate\Support\ServiceProvider; | |
class PaginationServiceProvider extends ServiceProvider | |
{ | |
/** | |
* Register the application services. | |
* | |
* @return void | |
*/ | |
public function register() | |
{ | |
Paginator::presenter(function ($paginator) { | |
return new MaterializeCssPresenter($paginator); | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment