Laravel Pagination Next Previous Button Example Tutorial

Jun 26, 2021 . Admin

Hi Dev,

Today, In this article i would like to share you how to create next previous button in laravel you can easily create next previous button in laravel 8 application.

So, we can add next and previous link on pagination utilizing simplePaginate() in laravel 8 application. laravel provide new eloquent method simplePaginate() for integrate simple pagination with only next previous button link.

Here, I will give you simple example of create next previous button in laravel so follow my steps.

Create Route
Path : routes/web.php
use App\Http\Controllers\HomeController;
use Illuminate\Support\Facades\Route;

| Web Routes
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!

Route::get('previous-next', [HomeController::class, 'index']);
Create Controller:

Next, In this step we will create a simple home controller just following command through.

Path : app/Http/Controllers/HomeController.php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Models\User;

class HomeController extends Controller
     * Write Your Code..
     * @return string
    public function index()
        $users = User::simplePaginate(5);
        return view('users', compact('users'));

Create Blade File

After Successfully create controller we can create a simpele blade file users.blade.php

Path : resources/views/users.blade.php
<!DOCTYPE html>
    <title>Laravel Next Previous Link Button Pagination -</title>
    <link rel="stylesheet" href="">
<body class="bg-dark"> 
<div class="container mt-5">
    <div class="row">
        <div class="col-md-8 offset-2">
            <div class="card">
                <div class="card-header">
                   <h5>Laravel Next Previous Link Button Pagination -</h5>
                <div class="card-body">
                    <table class="table table-bordered table-hover">
                        @foreach($users as $user)
                            <td>{{ $user->id }}</td>
                            <td>{{ $user->name }}</td>
                    {{ $users->links() }}


It will help you...

#Laravel 8 #Laravel