Level 75
You realize pagination and how to do it is covered in the documentation. And how to display them.
https://laravel.com/docs/6.x/pagination#displaying-pagination-results
my default view is index.blade.php, how can i redirect user from index.blade.php to next-pagination.blade.php when user click "next" or "back" button ? this is current code. The reason i want to change to next-pagination.blade.php because index and next-pagination have different layout design. i try to use withpath, but i confuse how to use it properly, like how can i pass my data from index to custom URI and then to another blade file.
//Article controller
$posts = Post::orderBy('created_at', 'desc')->simplepaginate(5);
return view('index.index', compact('posts'));
//Blade view
@foreach($posts as $post)
<div class="blog-post">
<h3 class="blog-post-title"><a href="/{{$post->categori}}/{{$post->slug_url}}">{{ $post->title }}</a></h3>
</div>
@endforeach
{{ $posts->links('index.pagination') }}
//custom pagination button pagination.blade.view
@if ($paginator->hasPages())
<nav class="blog-pagination">
@if ($paginator->onFirstPage())
<a class="btn btn-outline-secondary disabled" href="#" aria-disabled="true">Back</a>
@else
<a class="btn btn-outline-primary" href="{{ $paginator->previousPageUrl() }}">Back</a>
@endif
@if ($paginator->hasMorePages())
<a class="btn btn-outline-primary" href="{{ $paginator->nextPageUrl() }}">Next</a>
@else
<span class="btn btn-outline-secondary disabled" aria-disabled="true" href="#" >Next</span>
@endif
</nav>
@endif
//index folder
-- index.blade.php
-- pagination.blade.php
-- next-pagination.blade.php
Please or to participate in this conversation.