Laravel8 分页不能展示
Laravel8 的分页插件展示的问题:
larvel8 view视图分页组件默认使用 tailwindcss,教程中使用的还是基于 bootstrap 的一些样式,所以说要在程序的局部控制器方法中,或者
AppServiceProvider
的 boot 方法中增加强制使用 bootstrap 的方法调用。// 记着 use Illuminate\Pagination\Paginator; public function boot() { Paginator::useBootstrap(); }
前端页面的view视图的展示的方法
- 使用
render()
方法{!! $products->render() !!}
- 使用
links()
方法{!! $products->links() !!}
- 使用
需要增加的 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; } } } } } }
需要页面返回的数据超过
paginate(n)
每页展示的条数// 获取分页产品数据, 需要查询出来的商品超过 16 条 才能展示分页的效果,不然不会显示分页 $products = Product::query()->where('on_sale', true)->paginate(16);
推荐文章: