Last active
January 7, 2020 07:36
-
-
Save UnderlineWords/3c6efef4e44e7d5d9c52 to your computer and use it in GitHub Desktop.
Custom Laravel Pagination for Semantic UI - Laravel Documentation https://laravel.com/docs/master/pagination
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Semantic UI | |
* Includes previous and next buttons | |
* @example $pages->links('pagination-advanced', ['paginator' => $pages]) | |
* @example @include('pagination-advanced', ['paginator' => $pages]) | |
* | |
* @link https://semantic-ui.com/collections/menu.html#inverted Inverted styles | |
* @see <div class="ui pagination inverted blue menu"> Inverted blue menu | |
**/ | |
?> | |
@if ($paginator->lastPage() > 1) | |
<div class="ui pagination menu"> | |
<a href="{{ $paginator->previousPageUrl() }}" class="{{ ($paginator->currentPage() == 1) ? ' disabled' : '' }} item"> | |
Previous | |
</a> | |
@for ($i = 1; $i <= $paginator->lastPage(); $i++) | |
<a href="{{ $paginator->url($i) }}" class="{{ ($paginator->currentPage() == $i) ? ' active' : '' }} item"> | |
{{ $i }} | |
</a> | |
@endfor | |
<a href="{{ $paginator->nextPageUrl() }}" class="{{ ($paginator->currentPage() == $paginator->lastPage()) ? ' disabled' : '' }} item"> | |
Next | |
</a> | |
</div> | |
@endif |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Semantic UI | |
* @example $pages->links('pagination-simple', ['paginator' => $pages]) | |
* @example @include('pagination-simple', ['paginator' => $pages]) | |
**/ | |
?> | |
@if ($paginator->lastPage() > 1) | |
<div class="ui pagination menu"> | |
@for ($i = 1; $i <= $paginator->lastPage(); $i++) | |
<a href="{{ $paginator->url($i) }}" class="{{ ($paginator->currentPage() == $i) ? ' active' : '' }} item"> | |
{{ $i }} | |
</a> | |
@endfor | |
</div> | |
@endif |
@massuncao, the links() method accept a parameter where you can pass a view. e.g. In your blade files, you can use
{{ $posts->links('path.to.custom.view') }}
Please take a look at https://laravel.com/docs/5.5/pagination
Getting back to this.
when using any of the examples above, my pagination menu get's outside the boundaries of the page. Any idea on how to limit the size of the pagination menu to the size of the container where it is included?
Got it. The problema was in the controller, in the method paginate. i was doing it wrong.
Thanks for this! Very useful!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi.
This might seem an odd question. I am new to laravel and i am having trouble understanding how to use this code to include pagination in my project.
The thing is, these are two blade views, is there no code to add to the controller?