laravel 11 multiple files images upload with Preview

Uploading files or images in Laravel 11 is a crucial component of any project. Despite its significance, many developers encounter challenges when integrating file upload capabilities. Multiple image upload allows the user to select multiple files at once and upload all files to the server.

In this guide, I’ll demonstrate how to upload multiple files in Laravel 11, covering both single and multiple file uploads. We’ll utilize Laravel’s storage capabilities and create database records for the uploaded files. Throughout the tutorial, I’ll leverage Laravel 11 multiple files images upload functionality.

How to Upload Multiple Files in Laravel 11 with Preview

Follow the following steps to upload multiple images with preview and validation in Laravel 10 apps:

  • Step 1: Download Laravel App
  • Step 2: Setup Database credentials
  • Step 3: Generate Model & Migration
  • Step 4: Create Routes
  • Step 5: Generate Controller
  • Step 6: Create Blade View
  • Step 7: Run your application

#1 Download Laravel App

First, open the terminal or command prompt and run the following command to install a fresh Laravel app:

composer create-project laravel/laravel multiple-images

Next, go to the application directory:

cd multiple-images

#2 Connect Database

Open the .env file and add your database credentials such as database name, username and password.


#3 Create Model & Run Migration

Now, you need to generate model and migration file, execute the following command on terminal:

php artisan make:model Image -m

Next, add fillable properties in your model file. So, open the app\Models\Image.php file and put the following code on it.


namespace App\Models;

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

class Image extends Model
    use HasFactory;
    protected $fillable = [
        'name', 'path'

Next, open the database\migrations\2023_03_26_082159_create_images_table.php file and add the columns in it.


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()


Now run the migrate command and generate table in your database.

php artisan migrate

#4 Create Routes for Image upload

In this step, Navigate to the routes folder and open web.php file and add the following routes into web.php file:


use Illuminate\Support\Facades\Route;
use App\Http\Controllers\ImageController;

Route::get('images', [ ImageController::class, 'index' ]);
Route::post('images', [ ImageController::class, 'store' ])->name('');

#5 How to create Controller

Next generate a controller using the following command.

php artisan make:controller ImageController

After successfully creating the controller open and put the below code on it, Here we have added two methods on it one index for showing for form and the store function for saving data in database and uploading in public and storage directory.

So, open the app\Http\Controllers\ImageController.php file and put the login inside it;


namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Models\Image;

class ImageController extends Controller
    public function index()
       return view('images');
    public function store(Request $request)
            'images' => 'required',
            'images.*' => 'mimes:jpg,png,jpeg,gif,svg'

        if ($request->hasfile('images')) {
            $images = $request->file('images');
            foreach($images as $image) {
                $name = $image->getClientOriginalName();
                $path = $image->storeAs('uploads', $name, 'public');

                'name' => $name,
                'path' => '/storage/'.$path
        return back()->with('success', 'Images uploaded successfully');

#6 Create Blade File

Now create a images.blade.php file inside the resources/views directory. After that open the resources\views\images.blade.php file and put the below code on it;

<!DOCTYPE html>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Upload Multiple Files in Laravel with preview</title>
  <link rel="stylesheet" href="" />
        .invalid-feedback {
        display: block;
        .images-preview-div img
            padding: 10px;
            max-width: 150px;

    <div class="container mt-4">
      <h2>Upload Multiple Files in Laravel</h2>
            <div class="alert alert-success">
                {{ session()->get('success') }}
        <form method="post" action="{{ route('') }}" enctype="multipart/form-data">
          <div class="form-group">
              <input type="file" name="images[]" multiple class="form-control" accept="image/*" id="images">
              @if ($errors->has('images'))
                @foreach ($errors->get('images') as $error)
                <span class="invalid-feedback" role="alert">
                    <strong>{{ $error }}</strong>
          <div class="col-md-12">
              <div class="images-preview-div"> </div>
          <div class="form-group">
            <button type="submit" class="btn btn-success">Save</button>

    <script src=""></script>
        $(function() {
            // Multiple images preview with JavaScript
            var previewImages = function(input, imgPreviewPlaceholder) {
                if (input.files) {
                    var filesAmount = input.files.length;
                        for (i = 0; i < filesAmount; i++) {
                        var reader = new FileReader();
                        reader.onload = function(event) {
            $('#images').on('change', function() {
                previewImages(this, 'div.images-preview-div');

#7 Start your application

Now is the time to come to test Laravel multiple image upload with preview example.

So, run the following command on cmd to start the development server:

php artisan serve

Next open your browser and fire the following URL into a browser: