Niestandardowa paginacja laravela
php artisan vendor:publish --tag=laravel-pagination
ashik
php artisan vendor:publish --tag=laravel-pagination
$category = Category::first();
$apps = $category->apps()->paginate(10);
return view('example', compact('category', 'apps'));
# use default 'page' for this
$collection1 = Model::paginate(20);
# use custom 'other_page' for this
$collection2 = Model2::paginate(20);
$collection2->setPageName('other_page');
php artisan vendor:publish --tag=laravel-pagination
OR
use Illuminate\Pagination\Paginator;
public function boot()
{
Paginator::defaultView('your-pagination-view-name');
}
/**
* AppServiceProvider.php
*/
use Illuminate\Pagination\Paginator; // Don't forget this
public function boot ()
{
Paginator::useBootstrap(); // Add this
}
<?php
// config
$link_limit = 7; // maximum number of links (a little bit inaccurate, but will be ok for now)
?>
@if ($paginator->lastPage() > 1)
<ul class="pagination">
<li class="{{ ($paginator->currentPage() == 1) ? ' disabled' : '' }}">
<a href="{{ $paginator->url(1) }}">First</a>
</li>
@for ($i = 1; $i <= $paginator->lastPage(); $i++)
<?php
$half_total_links = floor($link_limit / 2);
$from = $paginator->currentPage() - $half_total_links;
$to = $paginator->currentPage() + $half_total_links;
if ($paginator->currentPage() < $half_total_links) {
$to += $half_total_links - $paginator->currentPage();
}
if ($paginator->lastPage() - $paginator->currentPage() < $half_total_links) {
$from -= $half_total_links - ($paginator->lastPage() - $paginator->currentPage()) - 1;
}
?>
@if ($from < $i && $i < $to)
<li class="{{ ($paginator->currentPage() == $i) ? ' active' : '' }}">
<a href="{{ $paginator->url($i) }}">{{ $i }}</a>
</li>
@endif
@endfor
<li class="{{ ($paginator->currentPage() == $paginator->lastPage()) ? ' disabled' : '' }}">
<a href="{{ $paginator->url($paginator->lastPage()) }}">Last</a>
</li>
</ul>
@endif