DEV Community

Cover image for Livewire OnScroll [Load More] laravel example - phpcodingstuff.com
Robert Look
Robert Look

Posted on

Livewire OnScroll [Load More] laravel example - phpcodingstuff.com

page scroll laravel livewire. In this tutorial we will learn how to implement load more data on page scroll in laravel 8 using livewire.

Sometimes, you want need load data on page scroll or infinity page scroll in laravel 8 using livewire.

In this tutorial, you will learn very easy step by step how to implement load more data on infinity scroll in laravel 8 with livewire package.

Livewire OnScroll [Load More] laravel example - phpcodingstuff.com

<?php

namespace App\Http\Livewire;

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

class LoadMoreUserList extends Component
{
    public $perPage = 15;
    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);
        $this->emit('userStore');

        return view('livewire.load-more-user-list', ['users' => $users]);
    }
}
Enter fullscreen mode Exit fullscreen mode

Top comments (0)