Laravel Pagination Pretty URL Example

About Us:

We are from free coder. We are a group of web developers who are passionate about web development. You can learn from us php, laravel, node js, vue js, react js and many other topic on web developement.
we are very happy to help you.
free coder

Today what you are going to learn:

Hello Brother, In this article, we will talk about laravel pagination pretty url. This tutorial will give you simple lesson 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 lesson.

You can use this lesson with laravel 6, laravel 7, laravel 8 and laravel 9 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 lesson:

Let's follow below steps:

Lesson 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 lesson-app

Lesson 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


Lesson 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');

Lesson 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('/');



Lesson 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 Lesson -</title>

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



<div class="container">

<h1>Laravel Pagination Pretty URL Lesson -</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:


thank you very much for following up with me.


Recent Posts

Related Posts