I trying to save a picture from vuejs frontend to laravel backend. I used jquey ajax to sent the form data.
var mydata = new FormData();
mydata.append('mypic', blob);
$.ajax(myurl, {
method: "POST",
headers: {
'Authorization':'Bearer ' + mytoken,
'Content-Type':'application/json'
},
data: mydata,
processData: false,
contentType: false,
success: function () {
console.log('Upload success');
},
error: function () {
console.log('Upload error');
}
});
In laravel, i tried
return $request->all();
but it returns an empty array. I also tried to log the $request with laravel Log
Log::info($request);
But it logs an empty array in the laravel.log
file
[2017-09-04 03:55:50] local.INFO: array (
)
I thought the formData.append()
was not working, so I log the formData
// Display the key/value pairs
for (var pair of mydata.entries()) {
console.log(pair[0]+ ', ' + pair[1]);
}
This worked well. It logs the entry I appended to fromdata. I don't understand why laravel Request facade is not getting it.
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire