我從刀片檔案 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 hljs-string">" 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);
}
uj5u.com熱心網友回復:
這是新版本 laravel 的問題。在您的App\Providers\AppServiceProvider類中,您需要在boot()函式內添加以下代碼以支持引導程式分頁器。
use Illuminate\Pagination\Paginator;
public function boot()
{
Paginator::useBootstrap();
}
在Blade的末尾</table>請添加這個。
<div class="d-felx justify-content-center">
{{ $items->links() }}
</div>
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/367077.html
