Build OnScroll Load More in Laravel 10 with Livewire Package

Last Updated on by in Laravel

Throughout this tutorial, you will determine how to load more data on page scroll in the laravel application using the laravel livewire package.

Load more or infinite scrolling is an immaculate way to show products, posts, or data on websites. Research says that scroll data loading is the best way to enhance user engagement; however, pagination is the traditional way to display data on websites.

This Laravel Livewire Load More OnScroll tutorial will help you implement the load more data on the scroll from scratch.

Livewire is a full-stack framework exclusively built for Laravel that reduces the pain of creating dynamic user interfaces without compromising on quality and keeps the warmth of Laravel.

Laravel 10 Livewire Load More OnScroll Example

Here are the steps towards building and implementing load more data on infinity scroll in the laravel application using the livewire package.

  • Create Laravel Project
  • Make Database Connection
  • Invoke Migration in Laravel
  • Generate Test Data
  • Install Livewire Package
  • Build Laravel Load More Component
  • Add Route in Laravel
  • Setting Up View
  • Test Application

Create Laravel Project

Make sure you have configured the composer on your development system. Head over to the console, open the terminal, enter the below command, and evoke the installation process:

composer create-project laravel/laravel laravel-load-more-example --prefer-dist

Make Database Connection

Open the .env file and add your database credentials such as database name, username equally important password:


If you are using MAMP local server in macOs; make sure to append UNIX_SOCKET and DB_SOCKET below database credentials in .env file.


Invoke Migration in Laravel

Next, you have to run the migration using existing laravel migration files. But make sure you started the development server if developing locally.

So head over to the console and execute the below command:

php artisan migrate

Generate Test Data

Now, to test the load more feature, you need to have test data in your database, so open the console and execute the following commands:

php artisan tinker

With the above command you entered inside the Psy Shell, further append the Model name and pass the number of the test records you are willing to generate:


Install Livewire Package

Use the composer command to install livewire library in laravel app:

composer require livewire/livewire

Build Laravel Load More Component

Now, you need to generate the livewire load more components with the following command.

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

Ultimately, the above command manifested two files on the following path:


Open and update the below code in app/Http/Livewire/LoadMoreUserData.php file:


namespace App\Http\Livewire;
use Livewire\Component;
use App\Models\User;

class LoadMoreUserData extends Component
    public $limitPerPage = 10;

    protected $listeners = [
        'load-more' => 'loadMore'
    public function loadMore()
        $this->limitPerPage = $this->limitPerPage + 6;

    public function render()
        $users = User::latest()->paginate($this->limitPerPage);

        return view('livewire.load-more-user-data', ['users' => $users]);

Open and update the below code in resources/views/livewire/load-more-user-data.blade.php file:

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

Add Route in Laravel

Next, add a route in the routes/web.php file; this will be a simple GET method to load users’ data on the scroll.


use Illuminate\Support\Facades\Route;

| Web Routes

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

Setting Up View

In this final step you have to open the resources/views/welcome.blade.php file and add the following code:

<!DOCTYPE html>
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Laravel Livewire Load More Data on Page Scroll Demo</title>
    <link href="" rel="stylesheet">
        body {
            height: 100vh;

    <div class="container mt-4">
    <script type="text/javascript">
        window.onscroll = function (ev) {
            if ((window.innerHeight + window.scrollY) >= document.body.offsetHeight) {



Test Application

Finally, you need to start the laravel application, so open the terminal window and execute the below command.

php artisan serve

Here is the URL on which you can test the app:



The Laravel Livewire Load More OnScroll tutorial is over; in this tutorial, we learned the easiest way to integrate on scroll loads more in the laravel application using the livewire library.

I reckon you liked this tutorial and share it with others.

Digamber - Author

Hi, I'm Digamber Singh, a New Delhi-based full-stack developer, tech author, and open-source contributor with 10+ years' experience in HTML, CSS, JavaScript, PHP, and WordPress.