In this tutorial im going to learn how to upload multi image in laravel in easy steps so follow these tutorials.
1st step create model and migration as like below command
php artisan make:model Multipic -m
![](https://www.devopsfreelancer.com/blog/wp-content/uploads/2023/09/image-38-1024x173.png)
Next go to your migration file
![](https://www.devopsfreelancer.com/blog/wp-content/uploads/2023/09/image-39-1024x408.png)
Next go to your model
![](https://www.devopsfreelancer.com/blog/wp-content/uploads/2023/09/image-40-1024x407.png)
Now migrate the table
php artisan migrate
![](https://www.devopsfreelancer.com/blog/wp-content/uploads/2023/09/image-41.png)
Next to create route
Route::get('/multi/image', [BrandController::class,'Multipic'])->name('multi.image');
Route::post('/multi/add', [BrandController::class,'StoreImg'])->name('store.image');
Next to create controller file
php artisan make:controller BrandController
Next to create 2 function as define below
public function MultiPic()
{
$images = Multipic::all();
return view('admin.multipic.index', compact('images'));
}
public function StoreImg(Request $request)
{
$image = $request->file('image');
foreach ($image as $multi_img) {
$name_gen = hexdec(uniqid());
$img_ext = strtolower($multi_img->getClientOriginalExtension());
$img_name = $name_gen . '.' . $img_ext;
$up_location = 'images/multi/';
$last_img = $up_location . $img_name;
$multi_img->move($up_location, $img_name);
Multipic::insert([
'image' => $last_img,
'created_at' => Carbon::now(),
]);
} // end foreach
return back()->with('success', 'images stored successfully');
}
Next go to view page and put form function only
<form action="{{ route('store.image')}}" method="POST" enctype="multipart/form-data">
@csrf
<div class="form-group mt-3">
<label for="">Brand Image</label>
<input type="file" name="image[]" class="form-control" id="exampleInputEmail1" aria-describedby="emailHelp" placeholder="image" multiple="">
</div>
<button type="submit" class="btn btn-primary">Add Image</button>
</form>
![](https://www.devopsfreelancer.com/blog/wp-content/uploads/2023/09/image-42-1024x412.png)
![](https://www.devopsfreelancer.com/blog/wp-content/uploads/2023/09/image-43-1024x544.png)
Next go to your view page where you want to show the output
<div class="card-group">
@foreach ($images as $multi)
<div class="col-md-4 mt-5">
<div class="card">
<img src="{{ asset($multi->image)}}" alt="">
</div>
</div>
@endforeach
</div>
![](https://www.devopsfreelancer.com/blog/wp-content/uploads/2023/09/image-44-1024x503.png)
Now working successfully. šš
[…] How to upload Multi Image in Laravel 9 ? […]