Join WhatsApp ChannelJoin Now

Laravel 10 Pagination Example

Hi Dev,

Are you trying to find an example of pagination with Laravel 10? It is a straightforward example of laravel 10 pagination using bootstrap 5. The idea behind the laravel 10 pagination tailwind example is clear. We’ll examine a case study demonstrating how to install pagination in Laravel 10. So, let’s examine an example in more detail.

We’ll conduct the migration in this example and make a “users” table. The tinker command will then be used to produce fake records. Then we will utilise pagination to display those users. By default, Laravel uses the Tailwind CSS design for pagination; in this article, we’ll utilise the Bootstrap 5 design.

So let’s follow few step.

Step 1: Install Laravel 10

Run command and install laravel

composer create-project laravel/laravel example-app

Step 2: Database Configuration


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

Step 3: Create Dummy Users

Let’s run 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:

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

I hope it will assist you…

Recommended Posts