1

I have a form that has multiple form file uploads - 6. So it looks like this :

<div class='form-group'>
  <div class='row'>
    <div class='col-md-12'>
      <div class='btn btn-info btn-md'>
        {!!Form::file('image-1')!!}

      </div>
    </div>
  </div>
</div>

<div class='form-group'>
  <div class='row'>
    <div class='col-md-12'>
      <div class='btn btn-info btn-md'>
        {!!Form::file('image-2')!!}
      </div>
    </div>
  </div>
</div>

In my controller, I don't want to have to do

if(Input::hasFile('image-1')||Input::hasFile('image-2')|| etc) {
  //code
}

plus each new image is a new row in my DB. I REALLY don't want to do

$image-1 = Image::create(); $image-2 = Image::create();

I guess for this I could throw everything into a array and loop through it, creating a object through each iteration...But I would still need to create an array with all the input objects which is annoying. Please show the way O_O

1 Answer 1

1

name all the file inputs like,

{!!Form::file('images[]')!!}

then images is an array

you can get the input in laravel as,

$images = Request::input('images');

then you can use foreach on $images array and do what you want.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.