当前位置:网站首页>Laravel customizes the paging style through the service provider
Laravel customizes the paging style through the service provider
2022-06-23 04:49:00 【Mamba kids' shoe】
Demand is introduced
Laravel Default paging , The implementation is very elegant , But sometimes you will encounter changing the default style , For example, I want to set the default <ul class="pagination"> It is amended as follows <ul class="pagination pagination-sm no-margin">
Solution entry point
Laravel The built-in paging link style is defined by Illuminate\Pagination\BootstrapThreePresenter Of render Method generation , We can make an article on this method .
Create override render Class of method
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 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() {
// Custom paging Paginator::presenter(function (AbstractPaginator $paginator) {
return new PagiationPresenter($paginator); }); } /** * Register the application services. * * @return void */ public function register() {
// } }Add service provider to config/app.php
'providers' => [
/*
* Laravel Framework Service Providers...
*/
...
App\Providers\PaginationServiceProvider::class,
],Link to the original text :http://blog.kesixin.xin/article/52
边栏推荐
猜你喜欢
随机推荐
Qt 及QT VS Tools插件官方下载及安装
在PCB板边走高频高速信号线的注意事项–高频高速信号设计基本原则
Examples of corpus data processing cases (part of speech encoding, part of speech restoration)
const理解之一
开关磁阻电机悬浮驱动IR2128小结
395. 冗余路径
8位全加器原理
PCB----理论与现实的桥梁
2022年起重机械安全管理考试题库及答案
QT elidedText 只对中文符合起作用,对英文不起作用的问题解决
2022 simulated examination question bank and answers for safety management personnel of metal and nonmetal mines (open pit mines)
laravel 8.4 路由问题,结尾处是编辑器左侧对照表,小白可看懂
TS进阶之infer
Leetcode 1208. Make strings as equal as possible
Distance measure - cosine distance
五年连续亏损42亿,蘑菇如何渡劫?
语料库数据处理个案实例(分词和分句、词频统计、排序)
如何解决独立站多渠道客户沟通难题?这款跨境电商插件一定要知道!
OGNL Object-Graph Navigation Language
Cocos learning diary 2 - scripts and attributes









