分页Laravel 5限制分页

时间:2015-07-27 20:09:50

标签: php pagination laravel-5

我的分页习惯是有效的,但我希望限制我的分页。

现在我的分页就是这样,

<< < 1 2 3 4 5 6 7 8 9 10 11 12 13> >>

但我希望像这样限制,

<< < 1 2 3 4 5> >> 当第5页有效时,

<< < 3 4 5 6 7> >>

关键是我要限制。因为我只想到如果我有1000页,这太糟糕了。

这是我的控制器

<?php

namespace App\Http\Controllers\Member;

use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;
use App\User;


class IncomeController extends Controller
{
    public function show()
    {
        $users = User::paginate(1);
        $users->setPath('income');
        return view('member.income.list')->with([
            'title' => 'Income Data',
            'userPage' => $users,
            ]);
    }
}

我的观点

@extends('app')
@section('content')
        <div class="row">
        <table border="1">
            @foreach($userPage as $users)
                <tr>
                    <td>{{$users->name}}</td>
                    <td>{{$users->last_online}}</td>
                </tr>
            @endforeach
        </table>


        @include('pagination.default',['paginator'=>$userPage])
        </div>
    <hr>
@stop

我的自定义分页视图

@if($paginator->lastPage()>1)
    <ul class="pagination">
        <li class="{{($paginator->currentPage()==1)?'disabled':''}}">
          <a href="{{$paginator->url(1)}}" aria-label="Previous">
            <span aria-hidden="true">&laquo;</span>
          </a>
        </li>
        <li class="{{($paginator->currentPage()==1)?'disabled':''}}">
          <a href="{{$paginator->url($paginator->currentPage()-1)}}" aria-label="Previous">
            <span class="fa fa-angle-left"></span>
          </a>
        </li>
        @for ($i=1; $i <= $paginator->lastPage(); $i++)
        <li class="{{($paginator->currentPage() == $i)?'active':''}}">
          <a href="{{$paginator->url($i)}}">
            {{$i}}
          </a>
        </li>
        @endfor
        <li class="{{($paginator->currentPage()==$paginator->lastPage())?'disabled':''}}">
          <a href="{{$paginator->url($paginator->currentPage()+1)}}" aria-label="Previous">
            <span class="fa fa-angle-right"></span>
          </a>
        </li>
        <li class="{{($paginator->currentPage()==$paginator->lastPage())?'disabled':''}}">
          <a href="{{$paginator->url($paginator->currentPage()+1)}}" aria-label="Next">
            <span aria-hidden="true">&raquo;</span>
          </a>
        </li>
    </ul>
@endif

0 个答案:

没有答案