【问题标题】:How to fix laravel 8 UI paginate problem?如何解决 laravel 8 UI 分页问题?
【发布时间】:2020-12-29 14:02:09
【问题描述】:

我在试用最近发布的 laravel 8 时遇到了一个问题,我正在尝试找出变化是什么以及它是如何工作的。当我这样做时,我遇到了分页 laravel 8 UI 变得混乱的问题,并且不知何故发生了。有谁能帮助我吗?或者有过同样的经历?

像这样我在 laravel 8 中得到的视图 Laravel 8 paginate UI

这是我使用“Index.blade.php”的代码

@extends('layouts.app')

@section('title', 'Post')

@section('contents')

    <div class="container">
        <div class="row">
            @foreach ($posts as $post)
                <div class="col-md-4 mb-4">
                    <div class="row">
                        <div class="card mb-4">
                            <div class="card-header">
                                {{ $post->title }}
                            </div>
                            <div class="card-body">
                                {{ $post->body }}
                            </div>
                            <div class="card-footer">
                                {{ $post->created_at->diffForHumans() }}
                            </div>
                        </div>
                    </div>
                </div>
            @endforeach
        </div>
        <div class="d-felx justify-content-center">

            {{ $posts->links() }}

        </div>
    </div>

@endsection

我用于 PostController 的代码

<?php

namespace App\Http\Controllers;

use App\Models\Posts;
use Illuminate\Http\Request;

class PostsController extends Controller
{
    public function index()
    {
        $posts = Posts::latest()->paginate(6);
        // dd($post);
        return view('post.index', compact('posts'));
    }
}

【问题讨论】:

标签: php laravel user-interface pagination laravel-8


【解决方案1】:

只要确保你的 AppServiceProvider 中有这个。

use Illuminate\Pagination\Paginator;

public function boot()
{
     Paginator::useBootstrap();
}

你可以走了。

【讨论】:

  • 哇。你节省了我的大量时间。谢谢
【解决方案2】:

我尝试在AppServiceProvider.php 中添加Paginator::useBootstrap();,但没有成功。

但这有效:

// Directly in your blade file
$posts->links('pagination::bootstrap-4')

【讨论】:

  • 它对我有用。但是我在这个 Laravel 项目中使用了 Bootstrap 5 版本。所以,分页看起来很有趣。 prntscr.com/1q9hnu8有什么办法可以使用Bootstrap 5?
  • 这很完美
  • 使用自定义分页设计,这在 laravel 8 上运行良好。感谢分享...
【解决方案3】:

首先进入文件 app\Providers\AppServiceProvider.php 并添加:

use Illuminate\Pagination\Paginator;

public function boot()
{
    
    Paginator::useBootstrap();
}

在 post.blade.php 中的 @endforeach 之后使用它:

{{ $blogs->links() }}

【讨论】:

    猜你喜欢
    • 2021-07-26
    • 2020-06-15
    • 2020-02-29
    • 2011-04-06
    • 1970-01-01
    • 2010-09-11
    • 2021-05-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多