Laravel:在分页中自定义页面链接

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/48828584/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 17:24:14  来源:igfitidea点击:

Laravel: customize page links in pagination

phplaravellaravel-5pagination

提问by Fred K

I'm building an app with Laravel 5.5. and I need to customize the pagination. I have to apply css class on the page link elements. Where I find the template to override?

我正在用 Laravel 5.5 构建一个应用程序。我需要自定义分页。我必须在页面链接元素上应用 css 类。我在哪里找到要覆盖的模板?

回答by doy

You have to launch this command from terminal:

您必须从终端启动此命令:

php artisan vendor:publish --tag=laravel-pagination

php artisan vendor:publish --tag=laravel-pagination

This creates the views in the resources/views/vendor/paginationdirectory.

这将在resources/views/vendor/pagination目录中创建视图。

Now you can apply your classes in the view: default.blade.php.

现在您可以在视图中应用您的类:default.blade.php

Read the documentation here: https://laravel.com/docs/5.6/pagination#customizing-the-pagination-view

在此处阅读文档:https: //laravel.com/docs/5.6/pagination#customizing-the-pagination-view

回答by Alexey Mezenin

You can specify your own pagination view:

您可以指定自己的分页视图:

{{ $paginator->links('view.name') }}

From the docs:

文档

By default, the views rendered to display the pagination links are compatible with the Bootstrap CSS framework. However, if you are not using Bootstrap, you are free to define your own views to render these links. When calling the links method on a paginator instance, pass the view name as the first argument to the method

默认情况下,渲染以显示分页链接的视图与 Bootstrap CSS 框架兼容。但是,如果您不使用 Bootstrap,您可以自由定义自己的视图来呈现这些链接。在分页器实例上调用 links 方法时,将视图名称作为第一个参数传递给该方法

Or you can customize the default view.

或者您可以自定义默认视图。

From the docs:

文档

However, the easiest way to customize the pagination views is by exporting them to your resources/views/vendordirectory using the vendor:publishcommand:

php artisan vendor:publish --tag=laravel-pagination

This command will place the views in the resources/views/vendor/paginationdirectory. The default.blade.phpfile within this directory corresponds to the default pagination view. Edit this file to modify the pagination HTML.

但是,自定义分页视图的最简单方法是resources/views/vendor使用以下vendor:publish命令将它们导出到您的目录:

php artisan vendor:publish --tag=laravel-pagination

此命令会将视图放置在resources/views/vendor/pagination目录中。default.blade.php此目录中的文件对应于默认的分页视图。编辑此文件以修改分页 HTML。

Or, if you've just modified default Bootstrap classes, you can just load CSS after Bootstrap is loaded.

或者,如果您刚刚修改了默认的 Bootstrap 类,则可以在加载 Bootstrap 后加载 CSS。

回答by Nikola Gavric

You need to publish the views first with php artisan vendor:publish --tag=laravel-paginationthen they will appear in your resources/views/vendor/paginationfolder and you can override them. Here is the reference

您需要先发布视图,php artisan vendor:publish --tag=laravel-pagination然后它们将出现在您的resources/views/vendor/pagination文件夹中,您可以覆盖它们。这是参考

This command will place the views in the resources/views/vendor/paginationdirectory. The default.blade.phpfile within this directory corresponds to the default pagination view. Simply edit this file to modify the pagination HTML.

此命令会将视图放置在resources/views/vendor/pagination目录中。该目录中的default.blade.php文件对应于默认的分页视图。只需编辑此文件即可修改分页 HTML。