Pagination Hello,
I am trying to create pagination for my blog but has not been successful yet.
blog.blade.php
@foreach($list as $blog)
<b><h3>{{ $blog->title }}</h3></b><br>
<br>
<img class="img-responsive" src="{{ url(Storage::url($blog->image)) }}" width="400px"><br><br>
{!! Str::limit($blog->content, 500, '...') !!}
<br><br>
<a href="#">Read More ..</a><br><br>
@endforeach
{{ $list->links('layouts.page') }}
layouts/page.blade.php
{{ $blogs->currentPage() }}
It suppose to be a normal pagination like: << 12 3 >>
I put the pagination in page in layouts folder.
ref: https://laravel.com/docs/6.x/pagination
Any clue how to?
I have tried that one and yes it works.
Now, I would like to know about custom pagination. Here I copy codes from other developers:
page.blade.php
@if ($paginator->hasPages())
<div class="pull-right">
{{-- Previous Page Link --}}
@if ($paginator->onFirstPage())
<span class="btn btn-default disabled"><span>«</span></span>
@else
<span class="btn btn-default"><a href="{{ $paginator->previousPageUrl() }}" rel="prev">«</a></span>
@endif
{{-- Pagination Elements --}}
@foreach ($elements as $element)
{{-- "Three Dots" Separator --}}
@if (is_string($element))
<span class="disabled"><span>{{ $element }}</span></span>
@endif
{{-- Array Of Links --}}
@if (is_array($element))
@foreach ($element as $page => $url)
@if ($page == $paginator->currentPage())
<span class="btn btn-danger active"><span>{{ $page }}</span></span>
@else
<span class="btn btn-default"><a href="{{ $url }}">{{ $page }}</a></span>
@endif
@endforeach
@endif
@endforeach
{{-- Next Page Link --}}
@if ($paginator->hasMorePages())
<span class="btn btn-default"><a href="{{ $paginator->nextPageUrl() }}" rel="next">»</a></span>
@else
<span class="btn btn-default disabled"><span>»</span></span>
@endif
</div>
@endif
What is $elements?
Was there perhaps a controller in the example you copied from? I could guess but would most likely be wrong? Perhaps you have a link to where you found it?
I copy the codes and it works on my system. I don't think there is another extra codes since I do not add anything to my system.
Please sign in or create an account to participate in this conversation.