Reputation: 1304
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?
Upvotes: 4
Views: 6231
Reputation: 555
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. |
+----------------------+-------------------------------------------------------------------+
Upvotes: 8
Reputation: 1304
I found out that you can access the total number of items and the items per page displayed for pagination. After that, it's easy to check if there is only one page - meaning there will be no pagination links to be shown.
@if ($items->total() > $items->perPage())
<div class="pagination-wrapper">
{{ $items->links() }}
</div>
@endif
Upvotes: 6