hamid pahlevani
hamid pahlevani

Reputation: 31

How to pass Multiple Image in form and catch in controller?

I have input tag in my form that get multiple image, but when I post form to my controller only last image passed.

this is my form

<form class="floating-labels m-t-40" method="post" action="{{asset(route('products.store'))}}" enctype="multipart/form-data" >
<input type="hidden" name="_token" value="{{csrf_token() }} ">
<input type="file" name="other_file[]" id="images" multiple="multiple"/>
</form>

when I dd($request) in my controller only show last image details.

Is there any hope?

Upvotes: 2

Views: 279

Answers (1)

Mohammed El Banyaoui
Mohammed El Banyaoui

Reputation: 527

For me It works like this:

if($request->hasFile('attachment'))
{
    $files = $request->file('attachment');
    foreach ($files as $file) {
       .....
    }
}

The html part

<input type="file" name="attachment[]" multiple>

Upvotes: 1

Related Questions