In pagination laravel not showing number I'm stuck with a problem in my laravel 9 web app. Pagination number not showing in the blade file. Only display the "Pagination.Previous" "Pagination.Next" link.
My code is In Controller:
$list = District::active()->orderBy('name')->paginate(10);
return view('district.list', compact('list'));
In view:
@if ($list->hasPages())
{{ $list->links() }}
@endif
So here what I did wrong?
Just use {{ $list->links() }}
@jlrdw already I used this and tried. but pagination numbrer not showing. Only prev and next link is displying.
@mahbubrn Do a dd and see how many results you get. And did you apply style to paginator?
@jlrdw
after dd I got this result. Screenshot link:
https://ibb.co/9g6F76v
Yes I have own custom css for pagination. But the page number not showing. Its not working.
@mahbubrn Just needed to know how many results? 10 or less? More than 10?
Try this one:
@if ($paginator->hasPages())
<ul class="pagination pagination">
{{-- Previous Page Link --}}
@if ($paginator->onFirstPage())
<li class="disabled"><span>«</span></li>
@else
<li><a href="{{ $paginator->previousPageUrl() }}" rel="prev">«</a></li>
@endif
@if($paginator->currentPage() > 3)
<li class="hidden-xs"><a href="{{ $paginator->url(1) }}">1</a></li>
@endif
@if($paginator->currentPage() > 4)
<li><span>...</span></li>
@endif
@foreach(range(1, $paginator->lastPage()) as $i)
@if($i >= $paginator->currentPage() - 2 && $i <= $paginator->currentPage() + 2)
@if ($i == $paginator->currentPage())
<li class="active"><span>{{ $i }}</span></li>
@else
<li><a href="{{ $paginator->url($i) }}">{{ $i }}</a></li>
@endif
@endif
@endforeach
@if($paginator->currentPage() < $paginator->lastPage() - 3)
<li><span>...</span></li>
@endif
@if($paginator->currentPage() < $paginator->lastPage() - 2)
<li class="hidden-xs"><a href="{{ $paginator->url($paginator->lastPage()) }}">{{ $paginator->lastPage() }}</a></li>
@endif
{{-- Next Page Link --}}
@if ($paginator->hasMorePages())
<li><a href="{{ $paginator->nextPageUrl() }}" rel="next">»</a></li>
@else
<li class="disabled"><span>»</span></li>
@endif
</ul>
@endif
Call it cpage.blade.php put directly in views folder and then:
{{ $list->links('cpage') }}
Edit:
If it works, go back and figure out how you are not calling the correct styles.
@jlrdw I already tried this command
php artisan vendor:publish --tag=laravel-pagination
And the above same code tried. But not working.
@mahbubrn Show controller, view, model code, and first make sure you are calling the correct view, otherwise if you have more than 10 results it would work.
@jlrdw Its worked.
php artisan vendor:publish --tag=laravel-pagination
{{ $list->links('vendor.pagination.default') }}
After fixing the correct view path. So why do I have to call a separate view file here? Why did the default system not work?
@mahbubrn Don't know, but just double check your code see if you missed something somewhere.
Glad you got it working.
Please sign in or create an account to participate in this conversation.