laravel 轻松实现分页功能

laravel 给我们提供了非常方便的分页工具----paginate分页器

使用方法:

1.逻辑层

public function getList( $id )
    {
        $where = ['pid' =>$id ]
        $list = $this->category->where($where)->orderBy('id','desc')->paginate(5);//$this->category对应为我的category对象,paginate函数里的参数为当前页面需要显示的条数

        return $list;
    }

2.前端页面

只需要

<div class="pull-right paginate">
        {{ $list->links() }}
</div>

只需要两步就可以完成该功能,是不是超级简单,如果只想显示上一页下一页,不要数字的那种分页,可以将paginate()函数替换成simplePaginate()即可

猜你喜欢

转载自www.cnblogs.com/MrBear/p/10298040.html