CoderFunda
  • Home
  • About us
    • Contact Us
    • Disclaimer
    • Privacy Policy
    • About us
  • Home
  • Php
  • HTML
  • CSS
  • JavaScript
    • JavaScript
    • Jquery
    • JqueryUI
    • Stock
  • SQL
  • Vue.Js
  • Python
  • Wordpress
  • C++
    • C++
    • C
  • Laravel
    • Laravel
      • Overview
      • Namespaces
      • Middleware
      • Routing
      • Configuration
      • Application Structure
      • Installation
    • Overview
  • DBMS
    • DBMS
      • PL/SQL
      • SQLite
      • MongoDB
      • Cassandra
      • MySQL
      • Oracle
      • CouchDB
      • Neo4j
      • DB2
      • Quiz
    • Overview
  • Entertainment
    • TV Series Update
    • Movie Review
    • Movie Review
  • More
    • Vue. Js
    • Php Question
    • Php Interview Question
    • Laravel Interview Question
    • SQL Interview Question
    • IAS Interview Question
    • PCS Interview Question
    • Technology
    • Other

23 February, 2021

Laravel 8 Vue Js Drag & Drop Image Upload Using Dropzone

 Programing Coderfunda     February 23, 2021     Laravel, laravel-tutorial     No comments   

 Laravel 8 Vue Js Drag & Drop Image Upload Using Dropzone


Laravel 8 Vue js dropzone example. In this tutorial, you will learn how to drag and drop multiple images or files for upload using vue-dropzone in laravel vue js apps.

Sometime, you work with laravel vue js apps. And at that time, you need to upload multiple files with showing a preview.

So this laravel vue-dropzone example will guide you on how to upload multiple image file and display preview in laravel vue js apps.

Laravel 8 Vue Js Multiple Image Upload Using Dropzone Example

  • Step 1: Install Laravel 8 App
  • Step 2: NPM Module Configuration For Vue Js
  • Step 3: Add Routes
  • Step 4: Create Controller By Command
  • Step 5: Create ImageUplaod Vue Component
  • Step 6: Create Blade Views And Initialize Vue Components
  • Step 7: Run Development Server

Step 1: Install Laravel 8 App

In this step, you need to install laravel latest application setup, So open your terminal OR command prompt and run the following command:

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

Step 2: NPM Module Configuration For Vue Js

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

1
php artisan preset vue

Install all Vue dependencies:

1
npm install

After that, install vue dropzone dependencies by using the below command:

1
npm install vue2-dropzone
Recommended:- Laravel 8 Vue JS Post Axios Request Tutorial

Step 3: Add Routes

Next step, go to routes folder and open web.php file and add the following routes into your file:

routes/web.php

1
2
3
use App\Http\Controllers\ImageController;
 
Route::post('store-multiple-image', [ImageController::class, 'store']);
Recommended:- Laravel 8 Vue JS File Upload Tutorial Example

Step 4: Create Controller By Command

Next step, open your command prompt and run the following command to create a controller by an artisan:

1
php artisan make:controller ImageController

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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
<?php
   
namespace App\Http\Controllers;
   
use Illuminate\Http\Request;
   
class ImageController extends Controller
{
    /**
     * success response method.
     *
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
        $imageName = time().'.'.$request->file->getClientOriginalExtension();
        $request->file->move(public_path('images'), $imageName);
          
        return response()->json(['success'=>'You have successfully upload file.']);
    }
}
Recommended:- Laravel 8 Vue JS Live Search Example

Step 5: Create ImageUplaod Vue Component

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

Now, update the following code into your MultipleImageUploadComponent.vue components file:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
<template>
    <div class="container">
        <div class="row justify-content-center">
            <div class="col-md-8">
                <div class="card">
                    <div class="card-header">Example Component</div>
                    <div class="card-body">
                        I'm an example component.
                        <vue-dropzone ref="myVueDropzone" id="dropzone" :options="dropzoneOptions"></vue-dropzone>
                    </div>
                </div>
            </div>
        </div>
    </div>
</template>
  
<script>
  
import vue2Dropzone from 'vue2-dropzone'
import 'vue2-dropzone/dist/vue2Dropzone.min.css'
   
    export default {
     components: {
        vueDropzone: vue2Dropzone
      },
      data: function () {
        return {
          dropzoneOptions: {
              url: '/store-multiple-image',
              headers: {
                "X-CSRF-TOKEN": document.head.querySelector("[name=csrf-token]").content
               }
          }
        }
      },
        mounted() {
            console.log('Component mounted.')
        }
    }
</script>

Now open resources/assets/js/app.js and include the  MultipleImageUploadComponent.vue component as follow:

1
2
3
4
5
6
7
8
9
require('./bootstrap');
  
window.Vue = require('vue');
  
Vue.component('multiple-image-component', require('./components/MultipleImageUploadComponent.vue'));
  
const app = new Vue({
    el: '#app'
});
Recommended:- Laravel 8 Vue Js Infinity Page Scroll Example

Step 6: Create Blade Views And Initialize Vue Components

Next, Navigate to resources/views/ and open welocome.blade.php. Then update the following code into your welcome.blade.php file as follow:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <meta name="csrf-token" content="{{ csrf_token() }}">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <title>Laravel Vue JS Multiple Image Upload Using vue-dropzone Example - Tutsmake.com</title>
        <link href="{{asset('css/app.css')}}" rel="stylesheet" type="text/css">
    </head>
    <body>
        <div id="app">
            <multiple-image-component></multiple-image-component>
        </div>
        <script src="{{asset('js/app.js')}}" ></script>
    </body>
</html>
Recommended:- How to implement Datatables with Vuejs And Laravel 8

Step 7: Run Development Server

Run the following command to start the development server:

1
2
3
npm run dev
or
npm run watch

 

  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg
Email ThisBlogThis!Share to XShare to Facebook
Newer Post Older Post Home

0 comments:

Post a Comment

Thanks

Meta

Popular Posts

  • JqueryUI - Show
    JqueryUI - Show, JqueryUI,  This chapter will discuss the show() method, which is one of the methods used to manage jQueryUI visual effe...
  • Real-Time Chat Package for Laravel
      Chatify   is a Laravel package by   Munaf Aqeel Mahdi   that adds a complete real-time chat system to your application without any additio...
  • WordPress Table
    WordPress Table WordPress table is an easy way to show the data in the table format. In the past, we had used the HTML code or table plugin ...
  • Python exec() Function
    Python exec() Function The python  exec()  function is used for the dynamic execution of Python program which can either be a string or obje...
  • CodeIgniter - Adding JS & CSS
    Adding JavaScript and CSS (Cascading Style Sheet) file in CodeIgniter is very simple. You have to create JS and CSS folder in root directo...

Categories

  • Ajax (26)
  • Bootstrap (30)
  • DBMS (42)
  • HTML (12)
  • HTML5 (45)
  • JavaScript (10)
  • Jquery (34)
  • Jquery UI (2)
  • JqueryUI (32)
  • Laravel (1017)
  • Laravel Tutorials (23)
  • Laravel-Question (6)
  • Magento (9)
  • Magento 2 (95)
  • MariaDB (1)
  • MySql Tutorial (2)
  • PHP-Interview-Questions (3)
  • Php Question (13)
  • Python (36)
  • RDBMS (13)
  • SQL Tutorial (79)
  • Vue.js Tutorial (69)
  • Wordpress (150)
  • Wordpress Theme (3)
  • codeigniter (108)
  • oops (4)
  • php (853)

Social Media Links

  • Follow on Twitter
  • Like on Facebook
  • Subscribe on Youtube
  • Follow on Instagram

Pages

  • Home
  • Contact Us
  • Privacy Policy
  • About us

Blog Archive

  • July (4)
  • September (100)
  • August (50)
  • July (56)
  • June (46)
  • May (59)
  • April (50)
  • March (60)
  • February (42)
  • January (53)
  • December (58)
  • November (61)
  • October (39)
  • September (36)
  • August (36)
  • July (34)
  • June (34)
  • May (36)
  • April (29)
  • March (82)
  • February (1)
  • January (8)
  • December (14)
  • November (41)
  • October (13)
  • September (5)
  • August (48)
  • July (9)
  • June (6)
  • May (119)
  • April (259)
  • March (122)
  • February (368)
  • January (33)
  • October (2)
  • July (11)
  • June (29)
  • May (25)
  • April (168)
  • March (93)
  • February (60)
  • January (28)
  • December (195)
  • November (24)
  • October (40)
  • September (55)
  • August (6)
  • July (48)
  • May (2)
  • January (2)
  • July (6)
  • June (6)
  • February (17)
  • January (69)
  • December (122)
  • November (56)
  • October (92)
  • September (76)
  • August (6)

Loading...

Laravel News

Loading...

Copyright © CoderFunda | Powered by Blogger
Design by Coderfunda | Blogger Theme by Coderfunda | Distributed By Coderfunda