Open bdjunayed opened 4 years ago
you should do it with FormData
:
/**
* Fetch all relevant data for the form.
*/
data() {
let data = new FormData();
for (let property in this.originalData) {
this.appendData(property,this[property],data);
}
return data;
}
appendData(key,value,appendTo){
if (value instanceof Array){
for (const i of value.keys() ){
this.appendData(`${key}[${i}]`,value[i],appendTo)
}
}
else if (typeof value === "object"
&& value !== null
&& !(value instanceof File))
{
for (const k in value) {
if (value.hasOwnProperty(k)) {
this.appendData(`${key}[${k}]`,value[k],appendTo);
}
}
}
else {
appendTo.append(key,value)
}
}
You need to use a FormData object if you want to send files. Checkout my pull request: https://github.com/laracasts/Vue-Forms/pull/27/files or check my video where I explain how FormData works: https://www.youtube.com/watch?v=kEy7w3KAtlc&t=445s
I am trying to send a file with these modification but received an empty array
[]
from the controller withdd()
. Could anybody can show me the way to do it.Form.js
ExampleComponent.vue