Please make image fillable using
protected $fillable=['image'];
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
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>```
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.
Please or to participate in this conversation.