Laravel 5.8 Multiple Image Upload with jQuery Add More Button

In this tutorial you will learn about the Laravel 5.8 Multiple Image Upload with jQuery Add More Button and its application with practical example.

Laravel 5.8 Multiple Image Upload with jQuery Add More Button

In this Laravel 5.8 Multiple Image Upload with jquery add more button example, we will learn how to upload multiple image using jquery add more button. In this laravel 5.8 multiple image upload example, I’ll show you how to validate and upload multiple image into folder and then save it into database. In this tutorial, we will use jquery to populate multiple image or file upload field. Before saving multiple image into database we will validate image and then save it into directory. After successfully uploading multiple images into the folder and saving it in database we will display success message on the screen.

Install Laravel 5.8

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

Configure Database In .env file

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.

.env

Generate Migration

Now, we have to define table schema for photos table. Open terminal and let’s run the following command to generate a migration file to create photos table in our database.

Once this command is executed you will find a migration file created under “database/migrations”. lets open migration file and put following code in it –

Run Migration

Now, run following command to migrate database schema.

After, the migration executed successfully the photos table will be created in database along with migrations, password_resets and users table.

Create Model

Next, we need to create a model called Photo using below command.

Once, the above command is executed it will create a model file Photo.php in app directory.

Create Controller

Now, lets create a controller for multiple image uploading. Create a controller named ImageUploadController using command given below –

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

app/Http/Controllers/jquery_multiple_image_upload/ImageUploadController.php

Here In the controller, we have following methods –

index() :- It displays Image Upload Form along with jQuery Add More Button.

store() :- To Upload and Save Multiple Image in database .

Note:- Before uploading any file make sure you have created following two directory in the public folder called profile_images.

Create Blade / View Files

In this step, we will create view/blade file to display Image Upload Form. Lets create a blade file “index.blade.php” in “resources/views/jquery_multiple_image_upload/” directory and put the following code in it respectively.

resources/views/jquery_multiple_image_upload/index.blade.php

jQuery Add More Button To File Upload Field Dynamically

Now, we will append a “Add” button to clone and append multiple file upload field to the form. Below is final view file code –

resources/views/jquery_multiple_image_upload/index.blade.php

Create Routes

After this, we need to add following routes in “routes/web.php” file along with a resource route. Lets open “routes/web.php” file and add following route.

routes/web.php

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 –

http://localhost:8000/jquery-multiple-image-upload

Output:-

laravel-5-8-multiple-image-upload-add-more-button-1

After Image Upload Screen Output:-

Click “Add” button to add Multiple Image files to upload control.

laravel-5-8-multiple-image-upload-add-more-button-2
Now, upload image.

laravel-5-8-multiple-image-upload-add-more-button-3

In this tutorial we have learn about the Laravel 5.8 Multiple Image Upload with jQuery Add More Button and its application with practical example. I hope you will like this tutorial.