I have an image uploader that allows multiple images on the frontend (vue.js). When I send it over to Laravel, it's not hitting my foreach
loop. I traced the print
logs to be executing up until the foreach
loops runs but I'm not sure why it's not going through each one unless that's not the correct way.
** JS **
let formData = new FormData();
this.files.forEach((x,index) => {
formData.append("file", x)
});
axios.post('/admin/upload', formData, {
headers: {
'Content-Type': 'multipart/form-data',
}
})
**Laravel **
print "outside";
if ($request->hasFile('file')) {
print "inside";
$files = $request->file('file');
$stack = [];
foreach ($files as $file) {
print "Looping";
$fileName = Storage::put('/trace/', file_get_contents($file->getRealPath()), ['visibility' => 'public']);
array_push($stack, $fileName);
}
return response()->json($stack);
}
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire