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:
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.
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:
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:
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:
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:
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:
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: