Laravel8 分页不能展示

Laravel8 的分页插件展示的问题:

  1. larvel8 view视图分页组件默认使用 tailwindcss,教程中使用的还是基于 bootstrap 的一些样式,所以说要在程序的局部控制器方法中,或者 AppServiceProvider 的 boot 方法中增加强制使用 bootstrap 的方法调用。

    // 记着 use Illuminate\Pagination\Paginator;
     public function boot()
     {
         Paginator::useBootstrap();
     }
  2. 前端页面的view视图的展示的方法

    1. 使用 render() 方法
      {!! $products->render() !!}
    2. 使用 links() 方法
      {!! $products->links() !!}
  3. 需要增加的 css 样式

    // page 首页商品列表分页
    .products-index-page {
    .products-list {
     padding: 0 15px;
     .product-item {
       padding: 0 5px;
       margin-bottom: 10px;
       .product-content {
         border: 1px solid #eee;
         .top {
           padding: 5px;
           img {
             width: 100%;
           }
           .price {
             margin-top: 5px;
             font-size: 20px;
             color: #ff0036;
             b {
               font-size: 14px;
             }
           }
           .title {
             margin-top: 10px;
             height: 32px;
             line-height: 12px;
             max-height: 32px;
             a {
               font-size: 12px;
               line-height: 14px;
               color: #333;
               text-decoration: none;
             }
           }
         }
         .bottom {
           font-size: 12px;
           display: flex;
           .sold_count span {
             color: #b57c5b;
             font-weight: bold;
           }
           .review_count span {
             color: #38b;
             font-weight: bold;
           }
           &>div {
             &:first-child {
               border-right: 1px solid #eee;
             }
             padding: 10px 5px;
             line-height: 12px;
             flex-grow: 1;
             border-top: 1px solid #eee;
           }
         }
       }
     }
    }
    }
  4. :star2::star2::star2: 需要页面返回的数据超过 paginate(n) 每页展示的条数

    // 获取分页产品数据, 需要查询出来的商品超过 16 条 才能展示分页的效果,不然不会显示分页
    $products = Product::query()->where('on_sale', true)->paginate(16);
Xiao Peng
laravel_peng
《L04 微信小程序从零到发布》
从小程序个人账户申请开始,带你一步步进行开发一个微信小程序,直到提交微信控制台上线发布。
《L01 基础入门》
我们将带你从零开发一个项目并部署到线上,本课程教授 Web 开发中专业、实用的技能,如 Git 工作流、Laravel Mix 前端工作流等。
讨论数量: 0
(= ̄ω ̄=)··· 暂无内容!

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!