Javatpoint Logo
Javatpoint Logo

Laravel VueJS File Upload Using Vue-dropzone Example

n this step, we are going to learn Vue-dropzone so that we can upload the VueJS file in Laravel. If we try to upload the file by adding the drag and drop option, there is an awesome way to do this is to choose dropzone js. In our example, we will use the Vue dropzone component to upload the VueJS file. For this, we can use laravel 6, Laravel 7, and Laravel 8. So in our VueJS script, dropzone js can also be used.

In order to file or image upload of Vue.js dropzone, we should follow a steps by step process. Firstly, the Laravel 5.6 will be downloaded. After that, VueJS will be initialized. Then we will install the package of Vue-dropzone. Now, one controller and one post route will be created by using the one method. We will use controller and create a POST method on it. After that, we will save the image by writing the following code. If we want to add more details, we can also write it. The step by step processes for file or image upload by using the components of Vue-dropzone is as follows:

Step 1:

This is the first step, and in this step, we are going to Install Laravel 5.6 project. For this, we will open the command prompt or terminal on our system and then run the following command.

Step 2:

In the second step, we are going to Create Route. For this, one post route will be created, and we will write code of file upload or image on it. So let's take that file and then put a new route like this:

routes/web.php

Step 3:

In the third step, we are going to Create Controller. Now we will create the formSubmit method and ImageController. We will use this method to store files or images on the server. So we will write code for that inside this method. For this, we will create a controller like this:

app/Http/Controllers/ImageController.php

Step 4:

In this step, we will do npm Configuration. For this, we will first add a VueJS setup. After that, we will install nmp and then also install the package of Vue-dropzone. We will use our project, and after that, we will use the following commands:

Install Vue:

Install npm:

Install Vue-dropzone:

Step 5:

In the fifth step, we are going to Write on components and app.js. For this, we will set the app.js path and then write code. After that, we are going to create components of VueJS. So we are going to create both the files and add the following code:

resources/assets/js/app.js:

resources/assets/js/components/ExampleComponent.Vue:

Step 6:

In the sixth step, we are going or Update welcome.blade.php file. For this, app/js file will be used. So we will update this file by writing the following code:

resources/views/welcome.blade.php:

The app.js file will be updated when we run the below command:

When we run the above example, we will get the following output:

Laravel VueJS File Upload Using Vue-dropzone Example





Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA