Laravel 8 - Livewire Load More On Page Scroll Step by Step

  4271 views   4 months ago Laravel

in this article, you'll learn how to enforce load more records on page scroll in laravel 8 with livewire.

Sometimes, you want to load information on web page scroll or infinity page scroll in laravel 8 with livewire. So, in this laravel livewire load more on page scroll educational, you will learn one by one how to implement load more data on infinity scroll in laravel 8 app with livewire package.

Load More On Page Scroll in Laravel 8 with Livewire Example.

1. Create Laravel Project
2. Configuration of Database
3. Set Up Migration and Add Dummy Data
4. Install Livewire
5. Create Load More Component
6. Create and Add Routes
7. Create Blade View
8. Run Development Server

Step 1: Create Laravel Project

first of all, we want to get a clean and new Laravel eight version application by the use of the bellow command, now open your terminal OR command prompt and then fire the bellow command and run it(However, you may ignore this step if the app is already created).

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

Step 2: Configuration of Database

Secondly, insert the database name, username, and password in .env file:

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

Step 3: Set Up Migration and Add Dummy Data

In this step, open your command prompt and run the following command to create the table into your database

php artisan migrate

This command will create table into your database.

Open terminal, execute the below commands to generate the test data

php artisan tinker



Step 4: Install Livewire

In this step, you need to install livewire package to your laravel project using the following command

composer require livewire/livewire

Step 5: Create Load More Component

In this step, create the livewire components for load more data using the following command in laravel. So Open your cmd and run the following command

php artisan make:livewire load-more-user-list

This command will create the following components on the following path



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

namespace App\Http\Livewire;
use Livewire\Component;
use App\Models\User;
class LoadMoreUserList extends Component
    public $perPage = 12;
    protected $listeners = [
        'load-more' => 'loadMore'
     * Write code on Method
     * @return response()
    public function loadMore()
        $this->perPage = $this->perPage + 5;
     * Write code on Method
     * @return response()
    public function render()
        $users = User::latest()->paginate($this->perPage);
        return view('livewire.load-more-user-list', ['users' => $users]);

After that, Navigate to resources/views/livewire folder and open load-more-user-list.blade.php file. Then add the following code into your load-more-user-list.blade.php file

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

Step 6: Create and Add Routes

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

Route::get('/load-more-scroll', function () {
    return view('lists');

Step 7: Create Blade View

In this step, navigate to resources/views/folder and create one blade view files that name lists.blade.php file. Then add the following code into your lists.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 8 Livewire Load More Data on Page Scroll</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 justify-content-center">
            <div class="col-md-8">
               <div class="card">
                  <div class="card-header">
                     <h2>Laravel 8 Livewire Load More Data on Page Scroll Example</h2>
                  <div class="card-body">
                     @if (session()->has('message'))
                     <div class="alert alert-success">
                        {{ session('message') }}
      <script type="text/javascript">
         window.onscroll = function(ev) {
         if ((window.innerHeight + window.scrollY) >= document.body.offsetHeight) {

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, you need to run the following PHP artisan serve command to start your laravel livewire load more data on page scroll app

php artisan serve

Now, you are ready to run laravel livewire load more on page scroll app. So open your browser and hit the following URL into your browser

Author : Harsukh Makwana
Harsukh Makwana

Hi, My name is Harsukh Makwana. i have been work with many programming language like php, python, javascript, node, react, anguler, etc.. since last 5 year. if you have any issue or want me hire then contact me on [email protected]