Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

RichardUnderwood's avatar

Laravel accessing file uploads in nested form data array

I posted this on SO but not getting much help and just realised this is a much better place to ask or so I hope as this is doing my head in at the moment.

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 and Request::input('request') won't contain the upload information.

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!

0 likes
7 replies
RichardUnderwood's avatar

@RachidLaasri I updated the post after I posted it, forgot to format the code block. The form has 'files'=> true and all that good stuff. Apart from that the form is a massive beast so I hope refining it down to just the input(s) in question is OK.

RachidLaasri's avatar

First time experiencing this kinda problems, i tried with :

$request->files->all();
$request->file('key');

Even

dd($_FILES);

Does not not show any results. I suggested doing some DOM manipulation and change the inputs with type of "file" name.

RichardUnderwood's avatar

@RachidLaasri Can you elaborate a bit on what you mean by doing some DOM manipulation and change the inputs with type of "file" name? Thanks

RichardUnderwood's avatar

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.

Jhourlad's avatar

The more "standard" way to do that would be:

$files = Input::file('request')[files];

foreach($files as $file) 
{
    print_r($file);
}
munazzil's avatar

Do you have used this in your input table <enctype="multipart/form-data">?

Please or to participate in this conversation.