Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Khin Zin Zin Thinn's avatar

SQLSTATE[42S22]: Column not found: 1054 Unknown column 'image' in 'field list' (SQL: insert into `multimgs` (`image`, `updated_at`, `created_at`) values (image/multimgs/1698482059909364.png, 2021-04-30 16:05:17, 2021-04-30 16:05:17))

I am trying to upload multiple images. But ended up with this error. Please suggest me what to do next.

This is the Code from Controller

<?php

namespace App\Http\Controllers;

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

class MultimgController extends Controller
{
    public function index() {
        $multimgs = Multimg::latest()->paginate(15);
        return view('admin.multimgs.index', compact('multimgs'));
    }

    public function store(Request $request) {

        $image = $request->file('image');

        foreach($image as $multimgs) {
            $img_name = hexdec(uniqid()).'.'.$multimgs->getClientOriginalExtension();
            $img_loca = 'image/multimgs/';
            Image::make($multimgs)->resize(300, 300)->save($img_loca.$img_name);
            $final_img = $img_loca.$img_name;

            $newMultimgs = new Multimg;
            $newMultimgs->image = $final_img;
            $newMultimgs->save();
        }

        return redirect()->back()->with('success', 'Images Have Been Added Successfully !');
    }
}

This is the Code from Model

<?php

namespace App\Models;

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

class Multimg extends Model
{
    use HasFactory;

    protected $fillable = ['image'];
}

This is the Code from Migration

public function up()
    {
        Schema::create('multimgs', function (Blueprint $table) {
            $table->id();
            $table->string('name');
            $table->timestamps();
        });
    }

This is the Code from Route

Route::get('/multimgs', [MultimgController::class, 'index'])->name('multimgs');
Route::post('/multimgs', [MultimgController::class, 'store'])->name('multimgs.store');

This is the Code from Blade

<x-app-layout>
    <x-slot name="header">
        <h2 class="font-semibold text-xl text-gray-800 leading-tight">
            Image Gallery
        </h2>
    </x-slot>

    <div class="container w-70">
        @if(session('success'))
            <div class="alert alert-success alert-dismissible fade show mt-5" role="alert">
                {{ session('success') }}
                <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
            </div>
        @endif
    </div>
    <div class="row container mx-auto mt-5">
        <div class="col-md-8">
            {{-- Image Gallery --}}
            <div class="card">
                <div class="card-header">
                    Image Gallery
                </div>
                <div class="card-body">
                </div>
            </div>
        </div>
        <div class="col-md-4">
            {{-- Add Images --}}
            <div class="card">
                <div class="card-header">
                Add Images
                </div>
                <div class="card-body">
                    <form action="{{ route('multimgs.store') }}" method="post" enctype="multipart/form-data">
                        @csrf
                        <div class="mb-3 mt-2">
                            <input type="file" class="form-control" name="image[]" id="exampleInputEmail1" aria-describedby="emailHelp" multiple="">
                            @error('image')
                                <small class="text-danger mt-2">{{ $message }}</small>
                            @enderror
                        </div>
                        <button type="submit" class="btn btn-outline-secondary mb-2">Submit</button>
                    </form>
                </div>
            </div>
        </div>
    </div>
    
    
</x-app-layout>```
0 likes
8 replies
aniketmagadum's avatar

Please make image fillable using

protected $fillable=['image'];

Khin Zin Zin Thinn's avatar

Hello Aniketmagadum,

Thanks for your suggestion. But I have already added that in the Model. Please suggest me something else.

aniketmagadum's avatar

It would be helpful if you post the code how are you trying to insert the data

Khin Zin Zin Thinn's avatar

Thanks for your answer. But I am doubtful that it would be a problem with the file upload since I am using the 'save()' method from the Intervention/Image.

siangboon's avatar
Level 54

the error telling you that the table "multimgs" does not have a column name "image"

and base on your migration file, the column should be "name"

so $newMultimgs->image is incorrect... and the $fillable is incorrect as well.

Khin Zin Zin Thinn's avatar

Thank you so much, siangboon. Your suggestion solved my problem. Have a nice day.

Please or to participate in this conversation.