Laravel访问嵌套数组中的文件上载

I need to build a form that allows multiple file uploads and also allows repeatable form groups. The form group that can be repeated contains upload fields which can be dynamically added too e.g add another file functionality.

One thing I can't figure out is how I can access the uploaded files if they're nested in an array in the request i.e Request::file('upload'); won't work.

Here's an example of the HTML of the file input and you can see the level of nesting that's going on.

<input class="js-file-input" name="request[0][files[]]" type="file" />

The request index is incremented for each new form group that's added to build up a list of requests made by a user on the app.

Any help would be greatly appreciated. Thanks!

I have tried this in my machine.

$inputs = Request::all();
var_dump($inputs);

    //prints
    array (size=2)
  '_token' => string 'jpY1dJy5t8' (length=40)
  'request' => 
    array (size=2)
      0 => string 'st2.jpg' (length=7)
      1 => string 'st2.jpg' (length=7)

Please try update your input field with following...

    <input class="js-file-input" name="request[0]files[]" type="file" />
    <input class="js-file-input" name="request[1]files[]" type="file" />

Just a follow up in case anyone is trying to do somethnig similar.I've made some progress, one way I can access the files is by supplying array keys.

So $file = Request::file('request')[0]['files'] will return all the files for the first nested files array so I can loop through and save them. I reckon by checking if each array has files with something like hasFile should work. Doesn't really feel like the right way to do it but it looks like it's the only way at the moment.

I needed to update the file input HTML to this:

<input class="js-file-input" name="request[0][files][]" type="file" />

Another way you can access the files is like this

$files = $request->request[0]['files'];