[Vuejs]-The given data was invalid. updating function with file uplaod in laravel 8 vue 2

0👍

first you should use sperate requests for both storing and updating.

Route::post('...', '...') // for store (called by this.axios.post() methods)
Route::put('...', '...') // for updating (called by this.axios.put() methods)

Second, make sure you will have to upload file not string, as postman shows you,
you will need to upload file by using FORMDATA as below:

 let config = {};
 let formData = new FormData();
 formData.append('file', this.file);
 formData.append('name', this.name); // other params as you want to send along
 ...
 
   this.axios.put(`/api/auth/outstanding-payment/${this.$route.params.id}`, formData, config)
   .then(function (response) {
     currentObj.success = response.data.success;
   })
   .catch(function (error) {
     currentObj.output = error;
   });

for reference you can see exmaple "Vue/laravel file upload example".

Leave a comment