如果第二页有一个项目,则在laravel 5.3中不显示分页

时间:2016-09-03 06:30:12

标签: laravel laravel-5 laravel-5.2 laravel-5.3

我们假设我们有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>
                                &nbsp;&nbsp;&nbsp;&nbsp;
                                <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>    

1 个答案:

答案 0 :(得分:1)

经过大量尝试后,我找到了解决方案:

update composer
php artisan vendor:publish --tag=laravel-pagination --force
php artisan view:clear

那就是它!