I'm not sure if I've phrased my question properly but I'm customizing pagination and so far I have this in my view and it's working well.
@if($paginator->hasPages())
<div class="pagination">
@if ($paginator->currentPage() > 1)
<a href="">«</a>
@else
<a href="" style="opacity:0.5; pointer-events:none;">«</a>
@endif
<a class="active" href="">1</a>
<a href="">2</a>
<a href="">3</a>
<a href="">4</a>
<a href="">5</a>
@if (!$paginator->hasMorePages())
<a href="" style="opacity:0.5; pointer-events:none;">»</a>
@else
<a href="">»</a>
@endif
</div>
@endif
As you can see the pages links are hard coded. How do I display them dynamically?
CodePudding user response:
Try replacing all that with
@if($paginator->hasPages())
{!! $paginator->render(); !!}
@endif
you can also
@if($paginator->hasPages())
<div class="pagination">
@if ($paginator->currentPage() > 1)
<a href="{{$paginator->previousPageUrl()}}">«</a>
@else
<a href="{{$paginator->url(1)}}" style="opacity:0.5; pointer-events:none;">«</a>
@endif
@if($paginator->currentPage()-2 >0)
<a href="{{$paginator->url($paginator->currentPage()-2)}}">{{$paginator->currentPage()-2}}</a>
@endif
@if($paginator->currentPage()-1 >0)
<a href="{{$paginator->url($paginator->currentPage()-1)}}">{{$paginator->currentPage()-1}}</a>
@endif
<a class="active" href="#">{{$paginator->currentPage()}}</a>
@if($paginator->currentPage() 1 <=$paginator->lastPage())
<a href="{{$paginator->url($paginator->currentPage() 1)}}">{{$paginator->currentPage() 1}}</a>
@endif
@if($paginator->currentPage() 2 <=$paginator->lastPage())
<a href="{{$paginator->url($paginator->currentPage() 2)}}">{{$paginator->currentPage() 2}}</a>
@endif
@if (!$paginator->hasMorePages())
<a href="{{$paginator->url($paginator->lastPage())}}" style="opacity:0.5; pointer-events:none;">»</a>
@else
<a href="{{$paginator->nextPageUrl()}}">»</a>
@endif
</div>
@endif
This code is not clean 100% but you get the idea (especialy aroud the $paginator->hasMorePages()
).