Laravel 7 Vue JS File Upload Example

In this tutorial you will learn about the Laravel 7 Vue JS File Upload Example and its application with practical example.

In this Laravel 7 Vue JS File Upload Example tutorial, I’ll show you how to upload file using Vue Js in laravel. In this tutorial you will learn to create file upload functionality using Vue Js in laravel.

Laravel 7 Vue JS File Upload Example

  • Step 1: Download Laravel Fresh App
  • Step 2: Add Database Detail
  • Step 3: Create Model And Migration
  • 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 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: Create Model And Migration

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

This command will create one model name photo.php and also create one migration file for the photos table.

Now open create_photos_table.php migration file from database>migrations and replace up() function with following code:

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

Step 4: NPM Configuration

Install all Vue dependencies:

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 FileUploadController using command given below –

After that, go to app\Http\Controllers and open FileUploadController.php file. Then update the following code into your FileUploadController.php file:

Step 7: Create Vue Component

Next step, go to resources/assets/js/components folder and create a filed called FileUpload.vue.

And update the following code into your FileUpload.vue components file:

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

Step 8: Register Vue App

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

Step 9: Run Development Server

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

In this tutorial we have learn about the Laravel 7 Vue JS File Upload Example and its application with practical example. I hope you will like this tutorial.