Reputation: 6612
I am using laravel 5.3.
I know that how can paginate large data set and how to work it.
Pagination links shown Even if just one page is require to show result. but I want to hide pagination links in this case?
I use render()
method to show pagination links like this :
<nav id="pagination">
{!! $posts->render() !!}
</nav>
Any idea?
Upvotes: 2
Views: 4049
Reputation: 2166
The best way to handle this is to hide the links to the pagination in your front-end if total <= per_page
.
If you're using laravel's links()
method you can do the following:
@if($results->total() > $results->perPage())
{{ $results->links }}
@endif
Upvotes: 4
Reputation: 1058
Here is better approach by undocumented method, for Laravel 5.0 and later.
@if ($results->hasPages())
{{ $results->links() }}
@endif
Link to method:
https://laravel.com/api/5.8/Illuminate/Contracts/Pagination/Paginator.html#method_hasPages
Upvotes: 1
Reputation: 6612
Because I want to apply this behavior to all paginations on the whole laravel project ,I used @Vuldo suggested approach to default.blade.php
view in the resources/views/vendor/pagination
directory like this :
@if($paginator->total() > $paginator->perPage())
<ul class="pagination">
...
</ul>
@endif
Upvotes: 0