Laravel Pagination Pretty URL Example

By Hardik Savani April 16, 2024 Category : Laravel

Hello all! In this article, we will talk about laravel pagination pretty url. This tutorial will give you simple example of how to make pagination pretty url in laravel. you'll learn laravel paginator pretty url. Here you will learn laravel pagination with pretty url example.

You can use this example with laravel 6, laravel 7, laravel 8, laravel 9, laravel 10 and laravel 11 version.

Laravel provides pagination default and it's working fine. But they generate URL with query strings and if you need to generate pretty url(seo friendly URL) for your pagination, Then I will help you with how you can do it.

Laravel Default Pagination URL:




Laravel Pagination with Pretty URL:




If you want to generate pretty url then just follow below step to done this example:


Let's follow below steps:

Step 1: Install Laravel

This step is not required; however, if you have not created the laravel app, then you may go ahead and execute the below command:

composer create-project laravel/laravel example-app

Step 2: Generate Dummy Users

In this step, we will generate some dummy users so we can make it pagination, so let's run tinker command and add new users:

php artisan tinker


Step 3: Create Routes

In this step, we will create two routes for users and another for pretty URL. so let's add it.



use Illuminate\Support\Facades\Route;

use App\Http\Controllers\UserController;



| 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('users', [UserController::class, 'index']);

Route::get('users/page/{page}', [UserController::class, 'index'])->name('users.index');

Step 4: Create Controller

In this step, we have to create new controller as UserController with index(). we will write logic of pagination on it. so let's update follow code:



namespace App\Http\Controllers;

use Illuminate\Http\Request;

use App\Models\User;

class UserController extends Controller



* Display a listing of the resource.


* @return \Illuminate\Http\Response


public function index(Request $request, $page = 1)


$paginate = 4;

$skip = ($page * $paginate) - $paginate;

$prevURL = $nextURL = '';

if ($skip > 0){

$prevURL = $page - 1;


$users = User::latest()




if($users->count() > 0){

if($users->count() >= $paginate){

$nextURL = $page + 1;


return view('users', compact('users', 'prevURL', 'nextURL'));


return redirect('/');



Step 5: Create View File

In Last step, let's create users.blade.php for create form with display validation message and put following code:


<!DOCTYPE html>



<title>Laravel Pagination Pretty URL Example -</title>

<link href="" rel="stylesheet">



<div class="container">

<h1>Laravel Pagination Pretty URL Example -</h1>

<table class="table table-bordered data-table">










@foreach($users as $user)


<td>{{ $user->id }}</td>

<td>{{ $user->name }}</td>

<td>{{ $user->email }}</td>





class="btn btn-info"







<div class="text-center">


<a class="btn btn-primary m-10 leftbtn" href="{{ route('users.index', $prevURL) }}"><i class="fa fa-angle-left" aria-hidden="true"></i> Previous</a>



<a class="btn btn-primary m-10 rightbtn" href="{{ route('users.index', $nextURL) }}">Next <i class="fa fa-angle-right" aria-hidden="true"></i> </a>






Run Laravel App:

All the required steps have been done, now you have to type the given below command and hit enter to run the Laravel app:

php artisan serve

Now, Go to your web browser, type the given URL and view the app output:


I hope it can help you...

Tags :