当前位置:网站首页>Laravel 通过服务提供者来自定义分页样式
Laravel 通过服务提供者来自定义分页样式
2022-06-23 03:51:00 【曼巴童鞋】
需求介绍
Laravel默认了分页,实现非常优雅,但有时候会遇到修改默认的样式,比如我要将默认的 <ul class="pagination">修改为 <ul class="pagination pagination-sm no-margin">
解决方法切入点
Laravel自带的分页链接样式由Illuminate\Pagination\BootstrapThreePresenter的render方法生成,我们在此方法上做文章即可实现。
创建重写render方法的类
创建文件: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 ''; } }创建服务提供者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() {
// } }将服务提供者添加到config/app.php
'providers' => [
/*
* Laravel Framework Service Providers...
*/
...
App\Providers\PaginationServiceProvider::class,
],边栏推荐
- PTA:7-65 饮料的价格
- Qt 及QT VS Tools插件官方下载及安装
- Tiktok x-bogus and_ Signature parameter analysis
- 【二叉树】二叉树的完全性检验
- thinkphp6 无关联ID的连表查询(2张表)主要是select的应用
- What are the characteristics of SRM supplier management system developed by manufacturing enterprises
- The spring recruitment in 2022 begins, and a collection of interview questions will help you
- [deep learning] deep learning reasoning framework tensorrt MNN openvino onnxruntime
- Leetcode 1208. Try to make the strings equal as much as possible (finally solved, good night)
- 五年连续亏损42亿,蘑菇如何渡劫?
猜你喜欢

论文阅读_关系抽取_CASREL

win10下安装、运行MongoDB

什么是元数据

在线JSON转CSharp(C#)Class工具

Notes on writing questions in C language -- free falling ball

Software development in 2022: five realities CIOs should know

【Pytorch】用自动微分求sin(x)的导数

距离度量 —— 余弦距离(Cosine Distance)

Cocos learning diary 2 - scripts and attributes

智能语音时代到来,谁在定义新时代AI?
随机推荐
How node+express operates cookies
Cool mouse following animation JS plug-ins 5
Prince language on insect date class
在线JSON转CSharp(C#)Class工具
PTA: price of 7-65 beverage
Pta:7-61 teacher student information management
Kail 渗透基本素养 基础命令
Permission Operation in dynamics 365 plug-in
The spring recruitment in 2022 begins, and a collection of interview questions will help you
1183. 电力
#17生成器的函数声明与调用
Pta:6-33 student ranking table (destructor)
How does flutter achieve different zoom animation effects
Cocos学习日记2——脚本和属性
PTA:6-73 函数调用
Chrome调试技巧
X24cxx series EEPROM chip C language universal reading and writing program
notepad++ 查找替换之分组替换保留
How to use MySQL index well
OpenJudge NOI 1.13 49:计算对数