假设我们有 11 个项目,我们设置每页 10 个项目,所以第二页将有 1 个项目,在这种情况下,第二页中的分页不显示,但是当添加另一个项目时,列表变为 12,第二页有 2 个项目显示分页。
控制器:
$cities = City::orderBy('id', 'desc')->paginate(10);
return view('cities.home', compact('cities'));
看法:
<div class="panel-body">
<div class="table-responsive panel panel-sky">
<table class="table table-striped table-hover">
<tr>
<th>#</th>
<th>Name</th>
<th>Created At</th>
<th>Action</th>
</tr>
@foreach($cities as $city)
<tr id="product{{$city->id}}">
<td>{{$city->id}}</td>
<td>{{$city->name}}</td>
<td>{{ $city->created_at }}</td>
<td>
<a href="{{ url('product/' . $city->id . '/edit') }}"><i class="glyphicon glyphicon-edit action-icon"></i></a>
<a type="button" class="pointer" data-toggle="modal" data-target="#deleteModal" data-type="btn-danger" data-action="delete-product" data-id="{{ $city->id }}" data-msg="Are you sure you want to delete this city?" data-title="Confirm Deletion">
<span class='glyphicon glyphicon-remove action-icon'></span>
</a>
</td>
</tr>
@endforeach
</table>
<div>
@if ($cities->total() > $cities->count())
<div class="col-md-12"><?php echo $cities->render(); ?> </div>
@endif
</div>