Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check if pagination links will be shown in laravel blade?

I'm using paginate for my pagination and I want to add custom markup for the $items->links() in Blade like this:

<div class="pagination-wrapper">
    {{ $items->links() }}
</div>

How do I check if the pagination links will be shown so that I won't print out an empty pagination-wrapper?

like image 492
jonan.pineda Avatar asked Sep 12 '25 07:09

jonan.pineda


1 Answers

On Laravel 5 or above there is even better and Laravel native way to check if pagination links will be shown in laravel blade.

@if ($items->hasPages())
    <div class="pagination-wrapper">
         {{ $items->links() }}
    </div>
@endif

From Laravel API documentation

+----------------------+-------------------------------------------------------------------+
|        Method        |                            Description                            |
+----------------------+-------------------------------------------------------------------+
| $results->hasPages() | Determine if there are enough items to split into multiple pages. |
+----------------------+-------------------------------------------------------------------+
like image 136
kuttumiah Avatar answered Sep 13 '25 22:09

kuttumiah