Laravel Pagination Example

Are you searching for the usage of the example blade of laravel pagination? I will provide a simple example with the solution if you have a question about laravel pagination with the user table. I clearly explained step by step laravel pagination example in the blade file. In Laravel 8, let’s talk about pagination.

We understand that pagination is a key requirement of each project. So if you’re a newcomer with laravel, you need to know how to use pagination in laravel and what other feature can be used with pagination with laravel.

I’ll describe you from scratch how to work with laravel pagination in this context. So let’s follow the below tutorial to build a quick pagination example with Laravel 8.

Read also How to create Laravel 8.0 project example
Laravel 8.0 pagination official doc here.

Step 1: Add Route

routes/web.php
Route::get('/users',[UserController::class,'get_all_users'])->name('get_all_users');

Step 2: Create Controller

app/Http/Controllers/UserController.php
<?php

namespace App\Http\Controllers;

use App\Models\User;
use Illuminate\Http\Request;

class UserController extends Controller
{

    public function get_all_users(){
        $users  = User::latest()->paginate(5);
        return view('user',compact('users'));
    }
}

Step 3: Create View

resources/views/user.blade.php
<!DOCTYPE html>

<html>

<head>

    <title>Laravel 8.0 Pagination Example</title>

    <link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.0.0-alpha/css/bootstrap.css" rel="stylesheet">

    <style>
        body{
            background-color: #2c3e50;
            color: white;
            margin-top: 100px;
        }
    </style>
</head>

<body>



<div class="container">

    <h1 class="text-center ">Laravel 8.0 Pagination Example</h1>

    <table class="table table-bordered mt-2">

        <thead>

        <tr>

            <th>Name</th>
            <th>Email</th>

            <th width="300px;">Action</th>

        </tr>

        </thead>

        <tbody>

        @if(!empty($users) && $users->count())

            @foreach($users as $key => $user)

                <tr>

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

                    <td>

                        <button class="btn btn-danger">Delete</button>

                    </td>

                </tr>

            @endforeach

        @else

            <tr>

                <td colspan="10">There are no data.</td>

            </tr>

        @endif

        </tbody>

    </table>



    {!! $users->links() !!}

</div>



</body>

</html>

Output

"Keyword" "laravel 8 pagination bootstrap" "pagination in laravel 7" "laravel pagination example blade" "laravel paginationbootstrap 4" "custom pagination laravel" "laravel pagination style" "laravel pagination with search" "laravel 5 6 pagination example"

Hope it will help !