【问题标题】:How to have laravel pagination links using the bootstrap 4 default pagination styles?如何使用 bootstrap 4 默认分页样式获得 laravel 分页链接?
【发布时间】:2018-10-19 18:32:40
【问题描述】:

我正在使用 laravel 默认分页: {{$posts->links()}} 并且分页工作,链接出现并且工作正常。

但是风格是这样的:

你知道为什么不使用 bootstrap 4 默认样式吗?我正在使用 Bootstrap 4。

我还有内部视图/供应商/分页文件:

- bootstrap4-blade.php
-default.blade.php
-semantic-ui.blade.php
-simple-bootstra-4.blade.php
-simple-default.blade.php

生成的 HTML:

<ul class="pagination">
    <li class="disabled"><span>«</span></li>
    <li class="active"><span>1</span></li>
    <li><a href="http://proj.test/user/profile?page=2">2</a></li>
    <li><a href="http://proj.test/user/profile?page=2" rel="next">»</a></li>
</ul>

在“http://proj.test/css/app.css”中出现:

.pagination {
  display: -webkit-box;
  display: -ms-flexbox;
  display: flex;
  padding-left: 0;
  list-style: none;
  border-radius: 0.25rem;
}

.page-item:first-child .page-link {
  margin-left: 0;
  border-top-left-radius: 0.25rem;
  border-bottom-left-radius: 0.25rem;
}

.page-item:last-child .page-link {
  border-top-right-radius: 0.25rem;
  border-bottom-right-radius: 0.25rem;
}

.page-item.active .page-link {
  z-index: 2;
  color: #fff;
  background-color: #0FACF3;
  border-color: #0FACF3;
}

.page-item.disabled .page-link {
  color: #868e96;
  pointer-events: none;
  background-color: #fff;
  border-color: #ddd;
}

.page-link {
  position: relative;
  display: block;
  padding: 0.5rem 0.75rem;
  margin-left: -1px;
  line-height: 1.25;
  color: #0FACF3;
  background-color: #fff;
  border: 1px solid #ddd;
}

.page-link:focus,
.page-link:hover {
  color: #097aad;
  text-decoration: none;
  background-color: #e9ecef;
  border-color: #ddd;
}

.pagination-lg .page-link {
  padding: 0.75rem 1.5rem;
  font-size: 1.25rem;
  line-height: 1.5;
}

.pagination-lg .page-item:first-child .page-link {
  border-top-left-radius: 0.3rem;
  border-bottom-left-radius: 0.3rem;
}

.pagination-lg .page-item:last-child .page-link {
  border-top-right-radius: 0.3rem;
  border-bottom-right-radius: 0.3rem;
}

.pagination-sm .page-link {
  padding: 0.25rem 0.5rem;
  font-size: 0.875rem;
  line-height: 1.5;
}

.pagination-sm .page-item:first-child .page-link {
  border-top-left-radius: 0.2rem;
  border-bottom-left-radius: 0.2rem;
}

.pagination-sm .page-item:last-child .page-link {
  border-top-right-radius: 0.2rem;
  border-bottom-right-radius: 0.2rem;
}

在页面加载中:

   <link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css?family=Nunito:200,400,600,700" rel="stylesheet">
    <link href="http://proj.test/css/app.css" rel="stylesheet" type="text/css">
    <link href="http://proj.test/css/toastr.min.css" rel="stylesheet" type="text/css">
    <link href="http://proj.test/css/bootstrap-datetimepicker.css" rel="stylesheet" />

【问题讨论】:

  • 您的页面中是否链接了引导程序?能否请您发布生成的 html 代码?
  • 是的,我正在使用其他 bootstrap 4 组件,我用它来更新问题。
  • 您确定 bootstrap.min.css 已与页面一起加载并且控制台中没有错误吗? &lt;link rel="stylesheet" href="/css/bootstrap/css/bootstrap.min.css"&gt;
  • 谢谢,页面中加载了css,在控制台出现错误但与datepicker“加载资源失败:服务器响应状态为404(未找到)”有关。跨度>
  • 谢谢,它似乎适用于 "{{$posts->links(("pagination::bootstrap-4"))}}"。

标签: laravel


【解决方案1】:

您可以自定义用于显示分页的视图,将其作为links 方法的参数传递:

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

您甚至可以自定义在您的AppServiceProvider 中使用Paginator::defaultView 应用的默认视图:

use Illuminate\Pagination\Paginator;

public function boot()
{
    Paginator::defaultView('pagination::view');
}

查看docs 了解更多信息。

【讨论】:

    【解决方案2】:

    由于该视图尚不可用,我们需要发布该视图。请在终端/CMD中运行以下命令:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-08-10
      • 2014-09-10
      • 2020-09-21
      • 1970-01-01
      • 2016-11-17
      相关资源
      最近更新 更多