Laravel 10 Pagination Example Tutorial

In Laravel, pagination refers to the process of dividing a large set of data into smaller, more manageable chunks called "pages." This is commonly used in web applications to display data in a structured and organized manner, allowing users to navigate through the data in a convenient way.

Step 1: Install Laravel App

composer create-project laravel/laravel example-pagination

Step 2: Database Configuration


DB_DATABASE=your database name
DB_USERNAME=database username
DB_PASSWORD=database password

Step 3: Create Dummy Users

migration command:

php artisan migrate

Next, run ticker command to add dummy users:

php artisan tinker

Step 4: Add Route


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

Step 5: Create Controller


    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(5);
            return view('users', compact('users'));

Step 6: Create Blade File


<!DOCTYPE html>
        <title>Laravel 10 Pagination Example -</title>
        <link href="" rel="stylesheet">
    <div class="container">
        <h1>Laravel 10 Pagination Example -</h1>
        <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') !!}

Run Laravel App:

php artisan serve

Now, Go to web browser, type the given URL and see the output: