I have a form that will have to save the images and also other inputed data and I want to use Async and await going to the api. this is the laravel controller
public function addbusiness(Request $request){
return response()->json(["message" => "up"]);
}
this is the vue js, this is my problem, i have errors in sending the data to the controller and the right way to pass it, what should i put when sending all the data to the controller using async await. and also save it to the database. It returns undefined.After the method post on the fetch api part, what to do next?
data() {
return {
items: [
{
rank_id: '1',
product_name: 'Multi Handle Tote Bag with Kalesa Scenery',
orders: 2500,
sales: '₱ 350,000',
rating: '5'
},
],
redirectChecked: false,
dropdownIndex: null,
selectedBarangay: 'Select Barangay',
barangayList: ['Bangkal', 'Bel-Air', 'Carmona', 'Dasmariñas', 'Forbes Park'],
searchQuery: '',
termsAndConditions: false,
addinfo: {},
busname: '',
bustype: '',
email: '',
contact: '',
country: '',
city: '',
barangay: '',
tin: '',
address: '',
clearance: '',
contractlease: '',
busregistration: '',
liabilityinsurance: '',
redirectweb: '',
lease: '',
clearance: '',
};
},
this is the function
methods: {
upclearance(event){
console.log(this.clearance = event.target.files[0])
},
uplease(event){
console.log(this.contractlease = event.target.files[0])
},
upregistration(event){
console.log(this.busregistration = event.target.files[0])
},
upinsurance(event){
console.log(this.liabilityinsurance = event.target.files[0])
},
async addbusinfo(e){
e.preventDefault();
const fd = new FormData();
fd.append('clearance', this.clearance, this.clearance.name);
fd.append('contractlease', this.contractlease, this.contractlease.name);
fd.append('busregistration', this.busregistration, this.busregistration.name);
fd.append('liabilityinsurance', this.liabilityinsurance, this.liabilityinsurance.name);
fd.append('busname', this.busname);
fd.append('bustype', this.bustype);
fd.append('email', this.email);
fd.append('contact', this.contact);
fd.append('country', this.country);
fd.append('city', this.city);
fd.append('barangay', this.barangay);
fd.append('tin', this.tin);
fd.append('address', this.address);
console.log(this.busname);
//console.log(fd);
await fetch("http://localhost:8000/api/addbusiness",{
method: 'POST',
data: fd,
}).then(response => {
console.log(response);
}).then(result => {
console.log(result);
});
}
},