【发布时间】: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->links() }}?因为工作的没有这行代码。
标签: php laravel laravel-pagination