我有城市表,它有 7 个城市 我有一个视图页面来显示这些城市,每页 10 个城市
控制器:
$cities = City::orderBy('id', 'desc')->paginate(10);
return view('cities.home', compact('cities'));
View:
<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>
<div class="col-md-12"><?php echo $cities->render(); ?> </div>
但问题是分页渲染显示为page#1,这个问题出现在laravel5.3中,在laravel5.2中没有找到
如果你想以自己的方式呈现分页,你可以使用paginator methods https://laravel.com/docs/5.3/pagination#paginator-instance-methods。例如,要检查是否只有一页,您可以尝试:
@if ($cities->total() > 10)
// Render pagination
@endif
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)