laravel的分页

一.因为大家对laravel框架的分页有些不满意,所以我在这里给大家写一个。

 $data = DB::Table('article')->paginate(5);//获取数据,以及写明分页时的数据个数。
        //print_r($data);die;
        $data->setPath('show');//
        $num=$data->lastPage();
        $next_page=$num-$data->currentPage() ==0 ? $num : $data->currentPage()+1 ;
        $last_page=$data->currentPage()-1 <0 ? 1 : $data->currentPage()-1 ;
        $data->next=$next_page;
        $data->last=$last_page;
        return view('article/article')->with('data',$data);

2.在views里写。

   @if ($data->LastPage()>1)
        <a href="{{ $data->Url(1) }}" class="item{{ ($data->CurrentPage() == 1) ? ' disabled' : '' }}">
            <i class="icon left arrow"></i>
            首页
        </a>  <a href="{{ $data->Url($data->last) }}" class="item{{ ($data->CurrentPage() == 1) ? ' disabled' : '' }}">
            <i class="icon left arrow"></i>
            上一页
        </a>  <a href="{{ $data->Url($data->next) }}" class="item{{ ($data->CurrentPage() == 1) ? ' disabled' : '' }}">
            <i class="icon left arrow"></i>
            下一页
        </a>
        <!--  @for ($i = 1; $i <= $data->LastPage(); $i++)
                <a href="{{ $data->Url($i) }}" class="item{{ ($data->CurrentPage() == $i) ? ' active' : '' }}">
            {{ $i }}
                </a>
            @endfor -->
        <a href="{{ $data->Url($data->LastPage()) }}" class="item{{ ($data->CurrentPage() == $data->LastPage()) ? ' disabled' : '' }}">
            末页
            <i class="icon right arrow"></i>
        </a>
    @endif

二.这样就是一个标准的分页了。

评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值