【问题标题】:Missing Bootstrap pagination page numbers in Laravel 8Laravel 8 中缺少 Bootstrap 分页页码
【发布时间】:2021-11-26 03:12:55
【问题描述】:

我将分页工作正常的刀片文件 B 中的表复制到刀片文件 A。但分页不适用于刀片文件 A。它确实显示了 10 个结果,但缺少页码导航。

这是一个截图供参考:

这是我的代码:

刀片文件A

<div class="row">
    <div class="col-xs-12 col-sm-12 col-md-12">
        <table class="table table-bordered">
            <tr>
                <th></th>
                <th>No</th>
                <th>Zone</th>
                <th>Code</th>
                <th>Description</th>
            </tr>
            @foreach ($items as $key => $item)
            <tr>
                <td>{{ Form::checkbox('item[]', $item->id, false, array('class' => 'name')) }}</td>
                <td>{{ $loop->index+1 }}</td>
                <td>{{ $item->zone }}</td>
                <td>{{ $item->code }}</td>
                <td>{{ $item->description }}</td>
            </tr>
            @endforeach
        </table>
    </div>
</div>

刀片文件B:

<table class="table table-bordered">
  <tr>
     <th>No</th>
     <th>Zone</th>
     <th>Code</th>
     <th>Description</th>
     <th width="280px">Action</th>
  </tr>
    @foreach ($items as $key => $item)
    <tr>
        <td>{{ ++$i }}</td>
        <td>{{ $item->zone }}</td>
        <td>{{ $item->code }}</td>
        <td>{{ $item->description }}</td>
        <td>
            {{-- <a class="btn btn-info" href="{{ route('items.show',$item->id) }}">Show</a> --}}
            @can('item-edit')
                <a class="btn btn-primary" href="{{ route('items.edit',$item->id) }}">Edit</a>
            @endcan
            @can('item-delete')
                {!! Form::open(['method' => 'DELETE','route' => ['items.destroy', $item->id],'style'=>'display:inline']) !!}
                    {!! Form::submit('Delete', ['class' => 'btn btn-danger']) !!}
                {!! Form::close() !!}
            @endcan
        </td>
    </tr>
    @endforeach
</table>

控制器 A:

public function create(Request $request)
{
    $items = Item::paginate(10);
    $sites = Site::get(["name", "id"])->all();
    // $states = State::all();
    // $cities = City::where("state_id",14)->get(["name", "id"]);
    return view('services.create', compact('sites', 'items'))
        ->with('i', ($request->input('page', 1) - 1) * 5);
}

控制器 B:

public function index(Request $request)
{
    $items = Item::orderBy('id', 'DESC')->paginate(10);
    return view('items.index', compact('items'))
        ->with('i', ($request->input('page', 1) - 1) * 5);
}

【问题讨论】:

  • @porloscerrosΨ 我应该在哪里添加{{ $items-&gt;links() }}?因为工作的没有这行代码。

标签: php laravel laravel-pagination


【解决方案1】:

这是新版本 laravel 的问题。 在您的App\Providers\AppServiceProvider 类中,您需要在boot() 函数中添加以下代码以支持引导分页器。

use Illuminate\Pagination\Paginator;

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

在 Blade 末尾 &lt;/table&gt; 请添加这个。

<div class="d-felx justify-content-center">
     {{ $items->links() }}
</div>

【讨论】:

  • 第一行代码是之前添加的。只是好奇,为什么刀片文件 B 可以在没有{{ $items-&gt;links() }} 的情况下工作?
  • 刀片文件在没有{{ $items-&gt;links() }} 的情况下工作,因为它只是为下一个分页数据提供链接。如果您不包含它,它不会破坏任何东西,您只是无法选择获取下一个数据。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-08-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-07-03
相关资源
最近更新 更多