Laravel 9 Livewire Pagination Example

Laravel 9 Livewire Pagination Example

Laravel 9 livewire pagination; In this tutorial, we will learn how to create laravel livewire pagination app using the default laravel pagination method with livewire components.

Note that, In this laravel livewire pagination, we will use default laravel pagination method to create pagination app using livewire in laravel.

Laravel 9 Livewire Pagination Example

Follow the following steps to create laravel 9 livewire pagination app:

  • Step 1: Download Laravel App
  • Step 2: Add Database Detail
  • Step 3: Create Model & Migration using Artisan
  • Step 4: Install Livewire Package
  • Step 5: Create a Pagination Component using Artisan
  • Step 6: Add Route
  • Step 7: Create View File
  • Step 8: Run Development Server

Step 1: Download Laravel App

First of all, Open terminal OR command prompt and run the following command to install laravel fresh app to create laravel livewire pagination app:

 composer create-project --prefer-dist laravel/laravel blog 

Step 2: Add Database Detail

In this step, Add database credentials in the .env file. So open project root directory and find .env file. Then add database detail in .env file:

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

Step 3: Run Migration

In this step, generate model, migration and faker file using the following command:

 php artisan make:model Employee -fm 

This command will create one model name Employee.php,create one migration that name create_employees_table.php and one faker file that name EmployeeFactory.php .

So, Navigate to database/migrations folder and open create_ employees_table.php file. Then update the following code into create_ employees_table.php file:

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateEmployeesTable extends Migration
     * Run the migrations.
     * @return void
    public function up()
        Schema::create('employees', function (Blueprint $table) {
     * Reverse the migrations.
     * @return void
    public function down()

Next, open command prompt and run the following command to create the table into database:

php artisan migrate

Next, Navigate to app/Models/Employee.php and update the following code into Employee.php model as follow:

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Employee extends Model
    protected $guarded = [];

Next, Navigate to database/factories and open EmployeeFactory.php. Then update the following code into it as follow:


use Faker\Generator as Faker;

$factory->define(App\Models\Employee::class, function (Faker $faker) {
    return [
        'name' => $faker->name,
        'email' => $faker->unique()->safeEmail

After that, run the following command to generate fake data using faker as follow:

php artisan tinker
//and then

Step 4: Install Livewire Package

In this step, we need to install livewire package to laravel project using the following command:

composer require livewire/livewire

Step 5: Create Component using Artisan

In this step, create the livewire components for creating a laravel livewire pagination component using the following command. So Open cmd and run the following command:

php artisan make:livewire pagination

This command will create the following components on the following path:


Now, Navigate to app/Http/Livewire folder and open Pagination.php file. Then add the following code into Pagination.php file:


namespace App\Http\Livewire;

use Livewire\Component;
use App\Models\Employee;

class Pagination extends Component

    public function render()
        $employees = Employee::latest()->paginate(10);
        return view('livewire.pagination',['employees' => $employees]);

After that, Navigate to resources/views/livewire folder and open pagination.blade.php file. Then add the following code into pagination.blade.php file:

    <div class="table-responsive">
        <table class="table table-bordered">
                @foreach($employees as $em)
                        <td>{{ $em->id }}</td>
                        <td>{{ $em->name }}</td>
                        <td>{{ $em->email }}</td>
        {{ $employees->links() }}

Step 6: Add Route

In this step, Navigate to routes folder and open web.php. Then add the following routes into web.php file:

Route::get('/livewire-pagination', function () {
    return view('livewire.home');

Step 7: Create View File

In this step, navigate to resources/views/livewire folder and create one blade view files that name home.blade.php file. Then add the following code into home.blade.php file:

<!DOCTYPE html>
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1">

        <title>Laravel 9 Livewire Pagination -</title>

        <!-- Fonts -->
        <link href=",600" rel="stylesheet">

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

        <!-- Styles -->
            html, body {
                background-color: #fff;
                color: #636b6f;
                font-family: 'Nunito', sans-serif;
                font-weight: 200;
                height: 100vh;
                margin: 0;

            .full-height {
                height: 100vh;

            .flex-center {
                align-items: center;
                display: flex;
                justify-content: center;

            .position-ref {
                position: relative;

            .top-right {
                position: absolute;
                right: 10px;
                top: 18px;

            .content {
                text-align: center;

            .title {
                font-size: 84px;

            .links > a {
                color: #636b6f;
                padding: 0 25px;
                font-size: 13px;
                font-weight: 600;
                letter-spacing: .1rem;
                text-decoration: none;
                text-transform: uppercase;

            .m-b-md {
                margin-bottom: 30px;
    <div class="container mt-5">
        <div class="row mt-5 justify-content-center">
            <div class="mt-5 col-md-8">
                <div class="card">
                  <div class="card-header bg-primary">
                    <h2 class="text-white">Laravel Livewire Pagination -</h2>

                    <div class="card-body">
Note that, if you want to add HTML(blade views), CSS, and script code into your livewire files. So, you can use @livewireStyles, @livewireScripts, and @livewire(‘ blade views’).

Step 8: Run Development Server

Finally, we need to run the following PHP artisan serve command to start laravel livewire pagination example app:

php artisan serve

If we want to run the project diffrent port so use this below command 

php artisan serve --port=8080  

Now, we are ready to run laravel livewire pagination app. So open browser and hit the following URL into browser:


Recommended Laravel Tutorials


Greetings, I'm Devendra Dode, a full-stack developer, entrepreneur, and the proud owner of My passion lies in crafting informative tutorials and offering valuable tips to assist fellow developers on their coding journey. Within my content, I cover a spectrum of technologies, including PHP, Python, JavaScript, jQuery, Laravel, Livewire, CodeIgniter, Node.js, Express.js, Vue.js, Angular.js, React.js, MySQL, MongoDB, REST APIs, Windows, XAMPP, Linux, Ubuntu, Amazon AWS, Composer, SEO, WordPress, SSL, and Bootstrap. Whether you're starting out or looking for advanced examples, I provide step-by-step guides and practical demonstrations to make your learning experience seamless. Let's explore the diverse realms of coding together.

Leave a Reply

Your email address will not be published. Required fields are marked *