Limited Time Offer!

For Less Than the Cost of a Starbucks Coffee, Access All DevOpsSchool Videos on YouTube Unlimitedly.
Master DevOps, SRE, DevSecOps Skills!

Enroll Now

How to upload Multi Image in Laravel 9 ?

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

Next go to your migration file

Next go to your model

Now migrate the table

php artisan migrate

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>

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>

Now working successfully. šŸ‘šŸ‘

Hi I am Amit Kumar Thakur Experienced as s Software Developer with a demonstrated history of working in the information technology and services industry. Skilled in HTML, CSS, Bootstrap4, PHP, Laravel-9 , REST API,FB API,Google API, Youtube Api, Bitbucket,Github,Linux and jQuery. Strong engineering professional focused in Computer/Information Technology Administration and Management. Currently my profile is to Software Developer, analyze the requirement, creating frame for web application, coding and maintenance.

Related Posts

How to Crawl any website Meta Title and Meta Description in Laravel ?

1st step install below package. Next to create Controller First go to route and put below code Next go to controller and put below code Next go…

SQLSTATE[HY000] [2002] No such file or directory (Connection: mysql, SQL: insert into `oauth_clients` (`user_id`, `name`, `secret`

In this tutorial i’m going to solve the error SQLSTATE[HY000] [2002] No such file or directory (Connection: mysql, SQL: insert into oauth_clients (user_id, name, secret Error :-…

Top 20 Laravel Interview Question in 2024

In this tutorial im going share interview experience For laravel developer. A list of top frequently asked Laravel Interview Questions and answers are given below. Q #1) What is…

How to Get Google Analytics API key ?

In this tutorial we’re going to share how to get the google Analytics API key. I have shared in very easy way. First go enable Google analytics…

Youtube Subscriber Count in ReactJs

In this tutorial iā€™m going to learn how to count YouTube Subsribers count, views count as well, as define below. In order to install your app, first…

How to Disable Laravel’s Eloquent timestamps in laravel ?

In this tutorial we’re going to share how to disable the automatic created_at and updated_at timestamps in Laravel’s Eloquent models, along with explanations of different scenarios: 1st…

0 0 votes
Article Rating
Subscribe
Notify of
guest
1 Comment
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
trackback

[…] How to upload Multi Image in Laravel 9 ? […]

1
0
Would love your thoughts, please comment.x
()
x