pagination in laravel 5.3 when count of pages = 1

谁说我不能喝 提交于 2019-12-10 19:39:53

问题


I have cities table and it has 7 cities I have a view page to display these cities with 10 cities per page

Controller:

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

but the issue is the paginate render is displayed with page#1, this issue occurred in laravel5.3 and did not find in laravel5.2


回答1:


If you want to render pagination in your own way, you can use paginator methods. For example, to check if there is just one page, you could try:

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


来源:https://stackoverflow.com/questions/39297189/pagination-in-laravel-5-3-when-count-of-pages-1

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!