当页数= 1时,laravel 5.3中的分页

时间:2016-09-02 16:40:45

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

我有城市表,它有7个城市我有一个查看页面显示这些城市每页10个城市

控制器:

    $cities = City::orderBy('id', 'desc')->paginate(10);
    return view('cities.home', compact('cities'));

查看:

<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>

               <div class="col-md-12"><?php echo $cities->render(); ?> </div>  

但问题是分页符渲染与页面#1一起显示,此问题发生在laravel5.3中,并且未在laravel5.2中找到

enter image description here

1 个答案:

答案 0 :(得分:0)

如果您想以自己的方式呈现分页,可以使用paginator methods。例如,要检查是否只有一个页面,您可以尝试:

@if ($cities->total() > 10)
    // Render pagination
@endif