Laravel 11 Simple Pagination Example

Websolutionstuff | May-03-2024 | Categories : Laravel

Hello developers! In this article, we'll see the laravel 11 simple pagination example. Here, we'll use Bootstrap 5 simple pagination in laravel 11. There are several ways to paginate items. The simplest is by using the paginate method.

The paginate method automatically takes care of setting the query's "limit" and "offset" based on the current page being viewed by the user.

Laravel's paginator is integrated with the query builder and Eloquent ORM and provides convenient, easy-to-use pagination of database records with zero configuration

Simple Pagination in Laravel 11

Laravel 11 Simple Pagination Example


Step 1: Install Laravel 11 Application

In this step, we'll install the laravel 11 application using the following command.

composer create-project laravel/laravel laravel-11-pagination


Step 2: Configure Database

Then, we'll configure the database into the .env file.



Step 3: Create Dummy Users

Next, we'll create a dummy record using the tinker.

php artisan tinker


Then, migrate the table into the database using the following command.

php artisan migrate


Step 4: Define a Route

Now, we'll define the route into the web.php file


use Illuminate\Support\Facades\Route;
use App\Http\Controllers\UserController;
Route::get('users', [UserController::class, 'index']);


Step 5: Create a Controller

Then, we'll create a controller and define the paginate() method.


namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Models\User;
use Illuminate\View\View;
class UserController extends Controller
     * Display a listing of the resource.
     * @return \Illuminate\Http\Response
    public function index(Request $request): View
        $users = User::paginate(10);
        return view('users', compact('users'));


Step 6: Create Blade File

Next. add the bootstrap 5 pagination using link() function.


<!DOCTYPE html>
    <title>Laravel 11 Simple Pagination Example -</title>
    <link href="" rel="stylesheet">
<div class="container">
    <div class="card mt-5">
        <h3 class="card-header p-3">Laravel 11 Simple Pagination Example -</h3>
        <div class="card-body">
            <table class="table table-bordered data-table">
                    @forelse($users as $user)
                            <td>{{ $user->id }}</td>
                            <td>{{ $user->name }}</td>
                            <td>{{ $user->email }}</td>
                            <td colspan="3">There are no users.</td>
            <!-- You can use Tailwind CSS Pagination as like here: -->
            <!-- {!! $users->withQueryString()->links() !!} -->
            {!! $users->withQueryString()->links('pagination::bootstrap-5') !!}


Pagination with appended parameter

{!! $data->appends(['sort' => 'votes'])->links() !!}

Pagination with appends requests all parameters

{!! $data->appends(Request::all())->links() !!}


Step 7: Run the Laravel 11 Application

Now, run the laravel 11 application using the following command.

php artisan serve


You might also like :

Recommended Post
Featured Post
Laravel Rollback Targeted Migration Reversals
Laravel Rollback Targeted Migr...

As a Laravel developer, I understand the significance of migrations in managing database changes and maintaining a consi...

Read More


How to Create Auto Generate Slug with Laravel Livewire
How to Create Auto Generate Sl...

Creating an auto-generating slug using Laravel Livewire is a practical and efficient way to handle slugs for your applic...

Read More


Laravel 8 One To One Relationship Example
Laravel 8 One To One Relations...

In this example we will see laravel 8 one to one relationship example also you can use one to one relationship in l...

Read More


How To Add Digital Signature In PDF In Laravel 9
How To Add Digital Signature I...

In this article, we will see how to add a digital signature in pdf in laravel 9. Here, we will learn to add a digit...

Read More