'Laravel $request->file('files') returns single uploaded file instead of many files
I am trying to upload multiple images via postman.
As you can see in the screenshot, I am using form-data and I have 2 files selected for upload.

In the controller method, I just have a dumper:
public function store(Request $request)
{
dd( $request->file('files') );
}
Here is what I get in response. 1 single file, although I uploaded 2 files, does anyone know what's wrong? Is this a postman bug or the code is wrong?

Solution 1:[1]
You need to define the name of the input as array.
<input type="file" name="attachments[]">
In PHP in the Controller Action do it like this:
if ($request->hasFile('attachments')) {
foreach ($request->attachments as $file) {
...
}
}
$file is the Illuminate\Http\UploadedFile
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Sascha |
