Laravel 7 Vue JS Infinite Scroll Example Tutorial
Laravel 12-Jan-2021

Laravel 7 Vue JS Infinite Scroll Example Tutorial

In this laravel vue js infinite scroll example tutorial, you will learn how to implement infinite page scroll with vue js components in laravel.

Suppose you build a blog application with vue js in laravel. And thousand of posts into your database and want to load all posts on single page when page scroll. So this tutorial will help you to display all posts on infinite page scroll with vue js in laravel.

This laravel infinite scroll vue example guide you from scratch on how to implement laravel infinite scroll vue app.

Laravel Vue JS Infinite Scroll

Follow following steps and implement infinite page scroll application with vue js in laravel:

Step 1: Download Laravel Fresh Setup

First of all, open your terminal and run the following command to download laravel fresh setup for laravel infinite scroll vue js app:

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


Step 2: Setup Database Credentials

In this step, Go to your project root directory and open .env file. Then set up database credential, as follow:

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

Step 3: Create Migration and Model File

Next step, run the following command on command prompt:

php artisan make:model Post -fm

This command will create post model, migration, and factory file into your project.

After that, Go to app/database/migrations and find posts migration file. Then open it and update the following code into your posts migration file:

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

After creating migration, open command prompt and run the following command:
php artisan migrate
This command will create tables into your database.

Step 4: Generate Dummy Data

Next step, generate fake or dummy data for posts table. So go to database/factories folder and find PostFactory.php file. After that, open and update the following code in PostFactory.php file as follow:

/** @var \Illuminate\Database\Eloquent\Factory $factory */
use App\Post;
use Faker\Generator as Faker;
$factory->define(Post::class, function (Faker $faker) {
    return [
        'title' => $faker->word,
        'slug' => strtolower($faker->word)

Next open terminal and run following command to generate dummy data for posts table:
php artisan tinker

Step 5: Add Route

In this step, Open web.php file, which is located inside blog/routes folder. And add the following routes into your web.php file:

Route::get('posts', 'PostController@index');

Step 6: Create Controller By Command

Again open a command prompt, to run the following command:

php artisan make:controller PostController

This command will create PostController inside app/Http/Controllers/ folder

Now, open your PostController and update the following methods into your PostController File:

namespace App\Http\Controllers;
use Illuminate\Http\Request;
class PostController extends Controller
    public function index()
        $data = \App\Post::orderBy('id')->paginate(10);
        return response()->json($data);

Step 7:  Configuration Vue JS

Now, you need setup Vue js. So open your terminal and run the following commands one by one:

Install npm:

npm install

Install vue-resource:

npm install vue-resource
Install vue-infinite-loading:

npm install vue-infinite-loading

Step 8: Update app.js And Default Components

Go to resources/assets/js/ folder and find the app.js file inside this directory. Then update the following code into your app.js file:


window.Vue = require('vue');
Vue.component('example-component', require('./components/ExampleComponent.vue').default);
Vue.component('InfiniteLoading', require('vue-infinite-loading'));
const app = new Vue({
    el: '#app',
    <div class="container" style="margin-top:50px;">
        <div class="row justify-content-center">
            <div class="col-md-8">
                <div class="card">
                    <div class="card-header"><strong> Laravel Vue JS Infinite Scroll -</strong></div>
                    <div class="card-body">
                          <p v-for="item in list" :key="">
                            <a v-bind:href="''+item.slug" target="_blank">{{item.title}}</a>
                          <infinite-loading @distance="1" @infinite="infiniteHandler"></infinite-loading>
    export default {
        data() {
            return {
              list: [],
              page: 1,
          methods: {
            infiniteHandler($state) {
                    .then(response => {
                        return response.json();
                    }).then(data => {
                        $.each(, (key, value)=> {
       = + 1;

Step 9:  Add Vue Components on welcome.blade.php file

Go to resources/views and find welcome.blade.php file inside this folder. Then update the following code into your welcome.blade.php file:


And also update the following code into app.blade.php file, which is located on resources/views/layouts/ folder.

<!doctype html>
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="csrf-token" content="{{ csrf_token() }}">
    <title>{{ config('', 'Laravel') }}</title>
    <link href="{{ asset('css/app.css') }}" rel="stylesheet">
    <div id="app">
        <main class="py-4">
 <script src="{{ asset('js/app.js') }}" defer></script>

Step 10: Run Development Server

Now run following command to update app.js file:

npm run watch