Next Previous Link Button Pagination Laravel

In this article, we will see the next previous link button pagination in laravel 8. Using paginate() function you can easily create pagination in laravel. we can create customize next and previous pagination links in laravel 8. The paginate method automatically takes care of setting the query's "limit" and "offset" based on the current page being viewed by the user.

So, let's see pagination in laravel 8, laravel pagination next previous, customize next and previous pagination link in laravel 8, and how to create pagination in laravel 8.

If you only need to display simple "Next" and "Previous" links on your website, then you can use the simplePaginate() method to perform a single, efficient query.

Example 1:

1. create a controller and add the below code.

namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Post;
class PostController extends Controller
    public function index()
        $posts = Post::simplePaginate(10);
        return view('posts.index', compact('posts'));



2. create a blade file.

      <title>Next Previous Link Button Pagination Laravel - Techsolutionstuff</title>
      <link rel="stylesheet" href=""/>
      <div class="container">
         <h1>Next Previous Link Button Pagination Laravel - Techsolutionstuff</h1>
         <table class="table table-bordered">
               @foreach($posts as $post)
                  <td>{{ $post->id }}</td>
                  <td>{{ $post->title }}</td>
         <div class="paginationWrapper">
            {{ $posts->links() }}


Example 2:

In this example, we will create custom pagination.

   @if($posts->currentPage() > 1)
      <a href="{{ $posts->previousPageUrl() }}">Previous</a>
      <a href="{{ $posts->nextPageUrl() }}">Next</a>


You might also like :


Techsolutionstuff | The Complete Guide

I'm a software engineer and the founder of Hailing from India, I craft articles, tutorials, tricks, and tips to aid developers. Explore Laravel, PHP, MySQL, jQuery, Bootstrap, Node.js, Vue.js, and AngularJS in our tech stack.