Laravel 8 Multiple Image Upload Tutorial



Sumit Suryavanshi


Upload multiple images in laravel 8 app. In this example, i will explain you how to upload multiple image file in laravel 8 app with validation. And as well as you will learn how to upload multiple files/images into the database table and folder in laravel. Also, you will learn how to validate multiple files/images on the server before uploading it into the folder and before inserting it into the database table.

Laravel 8 Multiple Image File Upload Example

  • Install Laravel 8 App
  • Configure Database Detail
  • Create Model and Migration
  • Run Migration
  • Create Routes
  • Generate Controller By Artisan
  • Create Blade View
  • Start Development Server

Install Laravel 8 App

First Step, you need to download or install laravel web application new setup on your local machine. you can use the following command to download or install laravel application new setup:

composer create-project laravel/laravel Laravel-Multiple-File-Upload –-prefer-dist

If you want to install a specific version of laravel, you can follow the following tutorial

Configure Database Detail

After that, you will set up the database credentials in .env file. So open your .env file and update database credentials following:


Create Model and Migration

Next, we need to create a model and migration in your laravel web application using the php artisan make:model model_name -m. So run the following command in your project root directory.

Go to the command prompt


php artisan make:model Image -m

after that, go to database/migrations/ and find created migration file and add fields, as you want to in your database table.

Your migration file looks like:


use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateImagesTable extends Migration
     * Run the migrations.
     * @return void
    public function up()
        Schema::create('images', function (Blueprint $table) {

     * Reverse the migrations.
     * @return void
    public function down()

And visit inside app/models/ directory and find image model file.

Your model file looks like:


namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class Image extends Model
    use HasFactory;

Run Migration

Next, go to command prompt and run the following command:

php artisan migrate
php artisan migrate:fresh

This php artisan migrate command creates a table in your database.

Create Routes

Next step, go to routes/web.php file and update the following routes into your file:

use App\Http\Controllers\ImageFileController;

Route::get('multiple-image-upload', [ImageFileController::class, 'index']);
Route::post('store', [ImageFileController::class, 'store']);

Generate Controller By Artisan

Now, you need to generate or create a controller file using artisan command, so use the php artisan make:controller command and generate/create a new controller file:

php artisan make:controller ImageFileController

In this controller file, we will create 2 methods for display file uploading form and store file into database and folder in laravel web application.

After that, go to App/Http/Controllers/ directory and find the created FileController file and update the following code into your file:


namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Validator,Redirect,Response;
Use App\Models\File;

class ImageFileController extends Controller

    public function index()
        return view('multiple-image-upload');

    public function store(Request $request)
        'fileName' => 'required',
        'fileName.*' => 'mimes:jpeg,png,jpg,gif,svg'
         foreach ($request->file('fileName') as $key => $value) 
           if ($files = $value) 
               $destinationPath = 'public/files/'; // upload path
               $fileName = date('YmdHis') . "." . $files->getClientOriginalExtension();
               $files->move($destinationPath, $fileName);
               $save[]['file_name'] = "$fileName";


        File::insert($save); // store file into mysql database

        return Redirect::to("multiple-image-upload")
        ->withSuccess('Images successfully uploaded.');


Create Blade Views

Next, you need to create a blade views file, so go resource/views directory and create the following blade views file.

Go to resource/views/ then create a new file name multiple-file-upload.blade.php and update the following code:

<html lang="en" class="">
<meta charset="UTF-8">
<title>Laravel 8 Multiple Image File Upload Example Tutorial</title>
<link rel="stylesheet" href="" />
<div class="container mt-5">
  <div class="row justify-content-center">
    <div class="card">
       <div class="card-header">Laravel Multiple Upload File Example</div>
         <div class="card-body">
            @if ($message = Session::get('success'))
                <div class="alert alert-success alert-block">
                    <button type="button" class="close" data-dismiss="alert">×</button>
                    <strong>{{ $message }}</strong>
            @if (count($errors) > 0)
                <div class="alert alert-danger">
                    <strong>Whoops!</strong> There were some problems with your input.<br><br>
                        @foreach ($errors->all() as $error)
                            <li>{{ $error }}</li>
            <form action="{{ url('/store') }}" method="post" enctype="multipart/form-data">
                <div class="form-group">
                    <input type="file" class="form-control-file" name="fileName[]" id="fileName" multiple="">
                <button type="submit" class="btn btn-primary">Submit</button>

Start development server

You can use the following command artisan command to start the development server:

php artisan serve

The final step, go to your browser and type the below-given URL into your browser: