Category Archives: Laravel

Laravel Tutorials

How to Create Laravel 8 Vue JS CRUD Single Page Application (SPA)

In this How to Create Laravel 8 Vue JS CRUD Single Page Application (SPA) Tutorial, I’ll show you how to create single page crud application using Vue Js in laravel. In this tutorial you will learn to create single page crud application using Vue Js in laravel 8. In this article we will be creating a basic single page crud application with vue js in laravel 8 application.

How to Create Laravel 8 Vue JS CRUD Single Page Application (SPA)

In this step by step tutorial I’ll demonstrate with example to create single page crud application using Vue Js in laravel 8. Please follow the instruction given below:

  • Create a Laravel Project
  • Enable database connection
  • Create a model and run migration
  • Create and configure the controller
  • Add routes
  • Install Laravel Vue UI
  • Install NPM dependencies
  • Build Vue Js CRUD Components
  • Test Laravel Vue JS CRUD operations

Install Laravel App

First of all we need to create a fresh laravel project, download and install Laravel 8 using the below command

Database Connection

Now, lets create a MySQL database and connect it with laravel application. After creating database we need to set database credential in application’s .env file.

Set Up Model and Run Migration

Now, in this step we will create model and migration file. Please run the following command:

Add following code in database/migrations/create_products_table.php:

Define Product table values in app/Models/Product.php:

Now, run the migration to create database table using following artisan command:

Create Product Controller

Now, lets create a controller named ProductController using command given below –

Open and update the below code in app\Http\Controllers\ProductController.php:

Create CRUD Routes

After this, we need to define routes in “routes/web.php” file. Lets open “routes/web.php” file and add the following routes in it.

routes/web.php

Now we need to define routes in “routes/api.php” file. Lets open “routes/api.php” file and add the following routes in it.

routes/api.php

Install Laravel Vue UI

In this step we will install laravel Vue UI using following commands:

After that, use the command to install the vue router and vue axios packages. These packages are used to consume Laravel CRUD APIs.


Now run the following command to install npm packages:


The npm run watch command compiles the assets, not just that with run watch command you don’t fret about re-run the compiler over and over again.

Initiate Vue in Laravel

Place below code in resources/views/layout/app.blade.php file:

Crete Vue CRUD Components

Next you need to create a App.js file in resources/js folder, put the following code in resources/js/App.js file:

Lets create some vue js component files inside the resources/js/components folder:

AllProduct.vue
CreateProduct.vue
EditProduct.vue

Add code in resources/js/components/AllProduct.vue file; in here we are getting all data from database and deleting single product object from database through vue component.

Place code in resources/js/components/CreateProduct.vue file:

Go to resources/js/components/EditProduct.vue template and add the below code:

Create Vue CRUD Routes

Now we will create Vue JS CRUD routes as following

Define Vue App.js

resources/js/app.js file:

Start Laravel Vue CRUD App

Now we are ready to run our example so lets start the development server using following artisan command –

Now, open the following URL in browser to see the output –

Create Datatables in Laravel 8 Vue JS Application

In this Create Datatables in Laravel 8 Vue JS Application Tutorial I’ll show you how to create Datatables in laravel Vue Js application. In this tutorial you will learn to create datatables with Vue Js in laravel. In this article I will give you example on how to use Datatables with Vue Js with example in laravel 8.

Create Datatables in Laravel 8 Vue JS Application

In this step by step tutorial I will demonstrate you with example on how to create Datatables with Vue Js in laravel 8. Please follow the instruction given below:

  • Create a laravel project
  • Make database connection
  • Generate and configure model, Run migration
  • Create routes
  • Generate and setting up the controller
  • Setting up vue UI in laravel
  • Configure a vue component
  • Setting up views and vue components
  • Run application

Install Laravel App

First of all we need to create a fresh laravel project, download and install Laravel 8 using the below command

Database Connection

Now, lets create a MySQL database and connect it with laravel application. After creating database we need to set database credential in application’s .env file.

Model and Migration

Now, in this step we will create model and migration file. Please run the following command:

Put the following code in database/migrations/create_blogs_table.php:

Now add following code in app/Models/Blog.php file:

Now, run the migration to create database table using following artisan command:

Add Test Data with Factory

In this step we will add some dummy data using following commands:

Next, add the code in database\factories\BlogFactory.php:

Run tinker command to get inside the Psy Shell:

Define Controller

Now, lets create a controller named BlogController using command given below –

Update the app\Http\Controllers\BlogController.php file:

Create Route

After this, we need to define routes in “routes/web.php” file. Lets open “routes/web.php” file and add the following routes in it.

routes/web.php

Install Laravel Vue UI

In this step we will install laravel Vue UI using following commands:

To install vue js datatable package, use the following command:


Then, run command to install npm dependencies:

Setting Up Vue JS in Laravel

Create BlogTable.vue in resources/js/components/ folder, place the following code in resources/js/components/DatatableComponent.vue file:

Create BlogTable.vue in resources/js/components/ folder, place the following code in resources/js/components/DatatableComponent.vue file:

Next, invoke the vue component by adding into the resources/views/welcome.blade.php file:

Add following code in resources/views/layout/app.blade.php:

Start Laravel Vue CRUD App

Now we are ready to run our example so lets start the development server using following artisan command –

Now, open the following URL in browser to see the output –

How to Create Infinite Scroll Load More in Laravel 8 Vue JS App

In this How to Create Infinite Scroll Load More in Laravel 8 Vue JS App tutorial I’ll show you how to create Infinite scroll load more in laravel 8 with Vue Js. In this tutorial you will learn to create Infinite scroll pagination or load more in laravel Vue Js . In this step by step guide I’ll share example of Vue JS Infinite Scroll Load More in laravel 8.

How to Create Infinite Scroll Load More in Laravel 8 Vue JS App

In this step by step tutorial I will demonstrate to create infinite scroll or load more on page scroll with vue js and laravel 8 applicatons. Please follow the instruction given below:

  • Create Laravel Project
  • Add Database Details
  • Create Model and Run Migration
  • Generate Dummy Data
  • Generate and Configure Controller
  • Create Route
  • Install Laravel Vue UI
  • Install Vue Infinite Loading
  • Set Up Vue JS in Laravel
  • Test Application

Install Laravel Project

First of all we need to create a fresh laravel project, download and install Laravel 8 using the below command

Add Database Details

Now, lets create a MySQL database and connect it with laravel application. After creating database we need to set database credential in application’s .env file.

Create Model and Run Migration

Now, in this step we will create model and migration file. Please run the following command:

Further, open the database/migrations/create_products_table.php file and add the table values within the migration of the product:

Open app/Http/Models/Product.php file and update the following code:

Now, run the migration to create database table using following artisan command:

Generate Fake Data

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

Further, put the below code in database\factories\ProductFactory.php:

Use the tinker command on the console to generate the test data into the database:

Generate and Configure Controller

Now, lets create a controller named ProductController using command given below –

Open app/Http/Controllers/ProductController.php file and update the below code:

Create Route

After this, we need to define routes in “routes/web.php” file. Lets open “routes/web.php” file and add the following routes in it.

routes/web.php

Install Laravel Vue UI

In this step we will install laravel Vue Js UI using following commands:

Now run below command to install the required npm dependencies:

Install Vue Infinite Loading

Now we will install Vue infinite loading  using following command.

Set Up Vue JS in Laravel

Create InfiniteScrollComponent.vue file in resources/js/components/ folder, add the following code in resources/js/components/InfiniteScrollComponent.vue file:

Next, Install the vue-resource package for enabling Vue single file components:


Then, open resources/js/app.js file and register the Vue JS component:

Further, add the vue component inside the resources/views/welcome.blade.php file:

Add following code in resources/views/layout/app.blade.php:

Test Application

Now we are ready to run our example so lets start the development server using following artisan command –

Now, open the following URL in browser to see the output –

Create Laravel 8 Auto Load More Data on Page Scroll with AJAX

In this Create Laravel 8 Auto Load More Data on Page Scroll with AJAX tutorial I’ll show you how to create infinity scroll or ajax auto load more data pagination on page scroll in laravel using ajax. In this tutorial you will learn to create dynamic auto load more data pagination in laravel using ajax in laravel. In this step by step guide I’ll share example of ajax load more or infinity scroll in laravel using ajax.

Create Laravel 8 Auto Load More Data on Page Scroll with AJAX

In this step by step tutorial I will demonstrate you how to create infinity scroll or ajax auto load more data pagination on page scroll in laravel. Please follow the instruction given below:

  • Step: 1 Create Laravel Project
  • Step: 2 Make Database Connection
  • Step: 3 Create Mode and Run Migration
  • Step: 4 Generate Dummy Data with Tinker Factory
  • Step: 5 Generate and Set Up Controller
  • Step: 6 Create Routes
  • Step: 7 Set Up View
  • Step: 8 Start server and Run Project

Create Laravel Project

First of all we need to create a fresh laravel project, download and install Laravel 8 using the below command

Make Database Connection

Now, lets create a MySQL database and connect it with laravel application. After creating database we need to set database credential in application’s .env file.

Create Mode and Run Migration

Now, in this step we will create model and migration file. Please run the following command:

Next, update the below code in database/migrations/create_blogs_table.php file:

Add following code in app/Models/Blog.php file:

Now, run the migration to create database table using following artisan command:

Add Test Data

In this step we will add some test data. Please run the following command:

Further, put the below code in database\factories\BlogFactory.php:

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

Generate and Set Up Controller

Now, lets create a controller named BlogController using command given below –

Further, add the following code in the app/Http/Controllers/BlogController.php file:

Create Route

After this, we need to define routes in “routes/web.php” file. Lets open “routes/web.php” file and add the following routes in it.

routes/web.php

Set up Blade View Template

In this step we will create blade view file. Lets create a blade file resources/views/welcome.blade.php. And put  the below HTML code into your resources/views/welcome.blade.php file:

resources/views/welcome.blade.php

Start server and Run Project

Now we are ready to run our example so lets start the development server using following artisan command –

Now, open the following URL in browser to see the output –

How to Get Previous and Next Record in Laravel

In this How to Get Previous and Next Record in Laravel Tutorial I will show you how to get the previous and next record in laravel. In this tutorial you will learn to get the previous and next record in laravel application. Working with any blog application in laravel we have to show the next or previous record in navigation. At that time we need to get the next or previous record from the database table.

How to Get Previous and Next Record in Laravel

In this step by step tutorial I’ll demonstrate you to get the next or previous record or data with URL in laravel. Please follow the instruction given below:

Get Next Record in Laravel

In laravel application next record can be accessed as following:

We have used the where(), first(), orderBy() likewise first() eloquent queries to get the next posts or records from the database.

Get Previous Record in Laravel

In laravel application previous record can be accessed as following:

We have used the where(), first(), orderBy() likewise first() eloquent queries to get the next posts or records from the database.

Access Prev / Next Records from Laravel Blade View

Below is example how to access previous and next records with url in blade view file.

Laravel 8 Create JSON Text File for Download using File and Response

In this Laravel 8 Create JSON Text File for Download using File and Response tutorial I will show you how to create json text file using file facade and download using response class in laravel. In this tutorial you will learn to create a json text file using file facade and then download it using laravel response class. In this article I will share example to create and download json text file in laravel application. In this tutorial you will learn convert form data or text file data into json format text file and download it using response class. We will be using laravel File facade class to create your own html file, txt file, php file etc as you want. File Facade Classis meant for laravel file handling with file facade you can create file, remove file, update file etc. We will also be using Laravel “Response” Class. In this example we will be using Laravel Response Class download that file.

Laravel 8 Create JSON Text File for Download using File and Response

In this step by step tutorial I will demonstrate you with example on how to create json text file using file facade and download using response class in laravel. Please follow the instruction given below:

Create Route

In this step we will define routes in “routes/web.php” file. Lets open “routes/web.php” file and add the following routes in it.

routes/web.php

Now, lets create a controller file named JsonController.php in app/Http/Controllers/ directory. Open the JsonController.php file and put the following code in it.

app/Http/Controllers/JsonController.php

Laravel 8 Socialite Login with Linkedin Tutorial Example

In this Laravel 8 Socialite Login with Linkedin Tutorial Example I’ll show you how to create LinkedIn login in laravel 8 using socialite. In this tutorial you will learn to integrate LinkedIn login with socialite in laravel. In this article we will create login with linkedin using socialite in laravel 8 application. In this example I will also guide you through the process to integrate login with linkedin using socialite in laravel.

Laravel Socialite Login with LinkedIn

As we all know that users are not much interested in filling up long registration form to register with any application. Allowing users to login with their social media accounts is quick and powerful way to get registered/verified users for your laravel application. Allowing users to login with their social media accounts makes registration/login process much easier, it also encourages more users to register for your application.

Laravel 8 Socialite Login with Linkedin Tutorial Example

In this step by step tutorial I will demonstrate you how to integrate linkedin login with socialite in laravel application. Please follow the instruction given below:

  • Step 1: Set Up Laravel Project
  • Step 2: Make Database Connection
  • Step 3: Install Jetstream Library
  • Step 4: Configure Socialite Pacakage
  • Step 5: Add and Migrate Linkedin Property in Users Table
  • Step 6: Add Linkedin Client ID and Secret
  • Step 7: Prepare Controller
  • Step 8: Define Routes
  • Step 9: Set Up Login View
  • Step 10: Start Laravel App

Set Up Laravel Project

First of all we need to create a fresh laravel project, download and install Laravel 8 using the below command

Make Database Connection

Now, lets create a MySQL database and connect it with laravel application. After creating database we need to set database credential in application’s .env file.

Install Jetstream Library

In this step, install jetstream laravel auth scaffolding package with livewire. Please follow the instruction.

Now run command to generate ready made auth templates:

Next, use command to install required npm packages:


Now, run the migration to create database table using following artisan command:

Configure Socialite Pacakage

In this step we will Install Socialite Package via Composer using following command:

Register socialite classes in config/app.php configuration file as suggested below:

Add and Migrate Linkedin Property in Users Table

In this step we will create a migration file. Please run the following command:

Thereafter add the new table values in the database/migration/add_social_auth_id_field.php file:

Next, open app/Models/User.php file and add new social auth fields within the file:

Finally, execute command to migrate new values into the user tabel:

Add Linkedin Client ID and Secret

In this step, we will create linkedin app for client and secret key, go to following link

Now create linkedin app filling the details and create your linkedin app. After creating the app set the redirect URL. Now, copy the client id and secret from linkedin app dashboard. Now, go to your project config directory and open service.php file. Then add linkedin app details in service.php file as following:

Prepare Controller

Now, lets create a controller named LinkedinController using command given below –

Once the above command executed, it will create a controller file LinkedinController.php in app/Http/Controllers/ directory. Open the LinkedinController.php file and put the following code in it.

app/Http/Controllers/LinkedinController.php

Define Routes

After this, we need to define routes in “routes/web.php” file. Lets open “routes/web.php” file and add the following routes in it.

routes/web.php

Set Up Login View

Now go to views/auth/login.blade.php file and create a login with linkedin button, add the route which allows making the login request:

Start Laravel App

Now we are ready to run our example so lets start the development server using following artisan command –

Now, open the following URL in browser to see the output –

Laravel 8 Socialite OAuth Login with Twitter Example Tutorial

In this Laravel 8 Socialite OAuth Login with Twitter Example Tutorial I’ll show you how to create OAuth Twitter login in laravel 8 using socialite. In this tutorial you will learn to integrate twitter login with socialite in laravel. In this article we will create login with twitter using socialite in laravel 8 application. In this example I will also guide you through the process to integrate login with twitter using socialite in laravel.

Laravel Socialite Login with Twitter

As we all know that users are not much interested in filling up long registration form to register with any application. Allowing users to login with their social media accounts is quick and powerful way to get registered/verified users for your laravel application. Allowing users to login with their social media accounts makes registration/login process much easier, it also encourages more users to register for your application.

Laravel 8 Socialite OAuth Login with Twitter Example Tutorial

In this step by step tutorial I will demonstrate you how to integrate twitter login with socialite in laravel application. Please follow the instruction given below:

  • Step 1: Install Laravel App
  • Step 2: Make Database Connection
  • Step 3: Install Laravel Livewire and Jetstream Packages
  • Step 4: Setting Up Socialite Library
  • Step 5: Update Social ID in Database
  • Step 6: Add Twitter Client ID and Secret
  • Step 7: Build Controller
  • Step 8: Add Routes
  • Step 9: Update Login View
  • Step 10: Run Development Server

Install Laravel App

First of all we need to create a fresh laravel project, download and install Laravel 8 using the below command

Make Database Connection

Now, lets create a MySQL database and connect it with laravel application. After creating database we need to set database credential in application’s .env file.

Install Laravel Livewire and Jetstream Packages

In this step, install jetstream laravel auth scaffolding package with livewire. Please follow the instruction.

composer require laravel/jetstream

After adding Jetstream, you need to install and build your NPM dependencies and migrate your database:

Setting Up Socialite Library

In this step we will Install Socialite Package via Composer using following command:

Open config/app.php file, plus add the following services in providers and aliases arrays:

Update Social ID in Database

In this step we will create a migration file. Please run the following command:

Get inside the database/migration/add_twitter_social_field.php file, add the given below properties migration file.

Additionally, open app/Models/User.php file and register the social login properties in here as well.

Now, run following command to migrate database schema.

Add Twitter Client ID and Client Secret

In this step we will create Twitter App for Twitter social login. Use the link provided to create twitter app.

After successfully create an app in twitter and get credentials from twitter dashboard, Set client id and client secret config/service.php file :

config/service.php

Build Controller

Now, lets create a controller named TwitterController using command given below –

Once the above command executed, it will create a controller file TwitterController.php in app/Http/Controllers/ directory. Open the TwitterController.php file and put the following code in it.

app/Http/Controllers/TwitterController.php

Add Routes

After this, we need to define routes in “routes/web.php” file. Lets open “routes/web.php” file and add the following routes in it.

routes/web.php

Update Login View

Go to views/auth/login.blade.php file, and create a login with Twitter button in the login template file.

Run Development Server

Now we are ready to run our example so lets start the development server using following artisan command –

Now, open the following URL in browser to see the output –

Build Secure PHP REST API in Laravel 8 with Sanctum Auth

In this Build Secure PHP REST API in Laravel 8 with Sanctum Auth Tutorial I will show you how to create REST API with Sanctum authentication In laravel. In this tutorial you will learn to create rest api with Sanctum authentication In laravel 8 application. In this article I will share example to create simple crud rest api with sanctum authentication in laravel. I will also show you how to install sanctum auth package in laravel. After installing and configure sanctum authentication in laravel we will create simple crud operation rest api.

Build Secure PHP REST API in Laravel 8 with Sanctum Auth

In this step by step tutorial I will guide you through create a fully functional restful API with sanctum authentication in Laravel 8. We will be creating fully functional REST API along with sanctum Authentication. Please follow the instruction given below:

  • Step 1: Create Laravel Project
  • Step 2: Add Database Details
  • Step 3: Install Laravel Sanctum Pacakage
  • Step 4: Setting Up Sanctum
  • Step 5: Update Model and Run Migration
  • Step 6: Build API Resources
  • Step 7: Set Up Controllers
  • Step 8: Create REST API Routes
  • Step 09: Test REST API in Postman

Create Laravel Project

First of all we need to create a fresh laravel project, download and install Laravel 8 using the below command

Add Database Details in ENV

Now, lets create a MySQL database and connect it with laravel application. After creating database we need to set database credential in application’s .env file.

Install Laravel Sanctum Pacakage

In this step, we will install Sanctum Package via the composer dependency manager. Use the following command to install Sanctum Package.

Setting Up Sanctum

Now, we need to publish the Sanctum configuration and migration files using the Artisan command.

Thereafter, register the sanctum middleware into the api array inside the app/Http/Kernel.php file

Now, run following command to migrate database schema along with sanctum tables in our database.


Lets Import the sanctum HasApiTokens service within the app/Models/User.php. Open App/User.php model file and add ‘Laravel\Sanctum\HasApiTokens’ trait in it.

Update Model and Run Migration

Now, in this step we will create migration file. Please run the following command:

Open and add code into the database/migrations/create_blogs_table.php file. Add few properties into the migration file as following.

Next, create an app/Models/Blog.php file and register product migration properties inside the $fillable array.

Now, run following command to migrate database schema.

Build API Resources

In this step we will create Blog resource api using following command:

Now, go to app/Http/Resources/Blog.php and replace with the provided code.

Setting Up Controllers

In this we will update controller files as following. Open app/Http/Controllers/API/BaseController.php file and put the following code in it.

Open and place all the suggested code into the app/Http/Controllers/API/AuthController.php file.

Now go to the app/Http/Controllers/API/BlogController.php file and insert the CRUD operations code into it:

Create REST API Routes

After this, we need to define routes in “routes/api.php” file. Lets open “routes/api.php” file and add the following routes in it.

routes/api.php

Test Sanctum REST API in Postman

Now we are ready to run our example so lets start the development server using following artisan command –

Test Register REST API

Test Login API

Create Post with Sanctum API

Get Single Post

Fetch All Posts

Update Post

Delete Record

Create Events in Laravel 8 using Fullcalendar and jQuery AJAX

In this Create Events in Laravel 8 using Fullcalendar and jQuery AJAX Tutorial I’ll show you how to create and display events on the calendar using fullcalendar and jquery ajax in laravel 8 application. In this tutorial you will learn to create and display events on the calendar using fullcalendar with jquery ajax in laravel 8. This tutorial you will also learn to show dynamic event data on calendar using fullcalendar and jquery ajax in laravel 8.

How to Create Laravel 8 Fullcalendar CRUD Events

In this step by step tutorial I will demonstrate you how to create events on the calendar using fullcalendar and jquery ajax in laravel 8 application. Please follow the instruction below:

  • Step 1: Create Laravel App
  • Step 2: Connect to Database
  • Step 3: Set Up Migration and Model
  • Step 4: Generate and Configure Controller
  • Step 5: Create and Add Routes
  • Step 6: Create Blade View
  • Step 7: Run Development Server

Create Laravel App

First of all we need to create a fresh laravel project, download and install Laravel 8 using the below command

Now switch into the project directory using following command:

Connect to Database

Now, lets create a MySQL database and connect it with laravel application. After creating database we need to set database credential in application’s .env file.

Set Up Migration and Model

Now, in this step we will create model and migration file. Please run the following command:

Now, open the app/Models/CrudEvents.php file and create a $fillable array and define the crud events values.

Further, add event_name, event_start and event_end values inside the database/migrations/create_crud_events_table.php file.

Now, run the migration to create database table using following artisan command:

Generate and Configure Controller

Now, lets create a controller named CalenderController using command given below –

Once the above command executed, it will create a controller file CalenderController.php in app/Http/Controllers/ directory. Open the CalenderController.php file and put the following code in it.

app/Http/Controllers/CalenderController.php

Create and Add Routes

After this, we need to define routes in “routes/web.php” file. Lets open “routes/web.php” file and add the following routes in it.

routes/web.php

Create Blade View

Open resources/views/welcome.blade.php file and put the following code in it.

Run Development Server

Now we are ready to run our example so lets start the development server using following artisan command –

Now, open the following URL in browser to see the output –

How to make dependent dropdown with Vue js and Laravel 8

In this Laravel 8 Vue js Dependent Dropdown Example tutorial, I’ll show you how to create dependent dropdown with Vue Js in laravel 8. In this tutorial you will learn to implement dependent dropdown with Vue Js in laravel 8. In this tutorial we will be creating simple country dependent dropdown example to demonstrate dependent dropdown example in laravel.

How to make dependent dropdown with Vue js and Laravel 8

In this step be step guide I will demonstrate you with example how to create dependent dropdown with Vue Js in laravel 8.

  • Step 1: Install Laravel 8 App
  • Step 2: Connecting App to Database
  • Step 3: Create Migration Files
  • Step 4: Create Models
  • Step 5: NPM Configuration
  • Step 6: Add Routes
  • Step 7: Create Controller By Command
  • Step 8: Create Vue Component
  • Step 9: Initialize Vue Components
  • Step 10: Run Development Server

Step 1: Install Laravel 8 App

First of all we need to create a fresh laravel project, download and install Laravel 8 using the below command

Step 2: Connecting App to Database

Now, lets create a MySQL database and connect it with laravel application. After creating database we need to set database credential in application’s .env file.

Step 3: Create Migration Files

Now, in this step we will create migration file. Please run the following command:

Let’s open create_countries_states_table.php migration file from database>migrations and replace up() function with the following code:

Now, in this step we will create model and migration file. Please run the following command:

Step 4: Create Models

Now, in this step we will create model file. Please run the following command:

Step 5: NPM Configuration

To calling Laravel API routes. You need to install vue-axios. So use run the following command on command prompt:


After installing all dependencies run this command:

Step 6: Add Routes

After this, we need to define routes in “routes/web.php” file. Lets open “routes/web.php” file and add the following routes in it.

routes/web.php

Step 7: Create Controller By Command

Now, lets create a controller named CountryStateController using command given below –

Now, go to app\Http\Controllers and open CountryStateController.php file. Then put the following code into your CountryStateController.php file:

Step 8: Create Vue Component

In this step we will create a Vue component. Go to resources/assets/js/components folder and create a filed called DropdownComponent.vue.

Now open resources/assets/js/app.js and include the FileUpload.vue component like this:app.js

Step 9: Initialize Vue Components

In this step, go to resources/views and create one folder named layouts. Inside this folder create one blade view file named app.blade.php file. Go to resources/views/layouts and open app.blade.php file. Then update the following code into your app.blade.php file as follow

Step 10: Run Development Server

Now we are ready to run our example so lets start the development server using following artisan command –

Laravel 8 Vue Js Form Submit with V form Package

In this Laravel 8 vue js form submit with v-form package tutorial I will show you how to submit form with V form package in laravel 8 with Vue Js. In this tutorial you will learn submit form data without refreshing the page using v-form package in laravel 8 with Vue Js. Before submit we will also validate the form data and display error message if validation fails.

Laravel 8 Vue Js Form Submit with V form Package

In this step by step tutorial I will demonstrate you how to use laravel vue js v-form package and Laravel Vue axios validation example. Please follow the instruction given below:

  • Step 1: Download Laravel Fresh App
  • Step 2: Add Database Detail
  • Step 3: Add On Migration File
  • Step 4: NPM Configuration
  • Step 5: Add Routes
  • Step 6: Create Controller By Command
  • Step 7: Create Vue Component
  • Step 8: Register Vue App
  • Step 9: Run Development Server

Step 1: Download Laravel Fresh App

First of all we need to create a fresh laravel project, download and install Laravel 8 using the below command

Step 2: Add Database Details

Now, lets create a MySQL database and connect it with laravel application. After creating database we need to set database credential in application’s .env file.

Step 3: Add On Migration File

In this step, you need to open create_users_table.php migration file from database>migrations and replace up() function with following code:

Now, run following command to migrate database schema.


Now, you need to update user model. Please put the following code in it.

App\Models\User.php

Step 4: NPM Configuration

You need to setup Vue and install Vue dependencies using NPM. So run the following command on command prompt:


Install all Vue dependencies:


Install v-form via npm

Step 5: Add Routes

After this, we need to define routes in “routes/web.php” file. Lets open “routes/web.php” file and add the following routes in it.

routes/web.php

Step 6: Create Controller By Command

Now, lets create a controller named AuthController using command given below –


Now, go to app\Http\Controllers and open AuthController.php file. Then put the following code into your AuthController.php file:

Step 7: Create Vue Component

Now, we will create a Vue compoent. Go to resources/assets/js/components folder and create a filed called FileUpload.vue. And put the following code into your RegisterComponent.vue components file:


Now open resources/assets/js/app.js and include the RegisterComponent.vue component like this:app.js

Step 8: Register Vue App

In this step, you will create a blade view file to define Vue’s app. Go to resources/views folder and make a file named app.blade.php. Then update the following code into app.blade.php as follow:


Now go to resources/views/auth/register.blade.php file and paste this code.

resources/views/auth/register.blade.php

Step 9: Run Development Server

Now we are ready to run our example so lets start the development server using following artisan command –