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

Database [] not configured Laravel in Laravel ?

In this tutorial i’m going to solve Database [] not configured in laravel. The error message “Database [] not configured Laravel” indicates that there is a missing…

How to send Notifications With Database In Laravel ?

In this tutorial we’re going to learn how to send notification if someone register on our software then send him notification. Install laravel project Next to create…

Cannot access offset of type string on string

In this tutorial i have to solve this error Cannot access offset of type string on string so follow this tutorial i have solved in this tutorials….

How to Generate Instagram Graph Api Access token ?

In this tutorial im going to generate instagram access token in very easy after reading this tutorial you’ll able to generate access token. 1st step Login Facebook…

How to get a Client IP address in Laravel

In this article, We will share with you how to get an IP address in your Laravel application with several way examples. What is IP address ?…

What is the difference between TRUNCATE and DELETE ?

TRUNCATE and DELETE are both used to remove data from a table in Laravel, but they have some important differences. What is TRUNCATE ? TRUNCATE is a…

0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x