当页面数= 1时在laravel 5.3中进行分页 [英] pagination in laravel 5.3 when count of pages = 1

查看:78
本文介绍了当页面数= 1时在laravel 5.3中进行分页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

控制器:

    $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中找到

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

推荐答案

如果要以自己的方式呈现分页,则可以使用

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

这篇关于当页面数= 1时在laravel 5.3中进行分页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆