[Vuejs]-Uploading pdf file in laravel vuejs Axios

0👍

The given data was invalid.”,”errors”:{“file”:[“The file field is required. This error is because there is no existing file in your payload upon submission of your form.

in your form, bind data to your input file like what you did to your input name. like this

<input
      type="file"
      v-model="form.file"
      class="form-input"
      :class="{ 'is-invalid': form.errors.has('file') }"
       id="file"
      name="file"
 />

Or, attach an event to this file input and process the file provided. like this

<input
          type="file"
          class="form-input"
          :class="{ 'is-invalid': form.errors.has('file') }"
          id="file"
          name="file"
          @change="selectFile"
/>

Then in your methods, create also a selectFile function

methods: {
    selectFile(file) {
         if(file == "") return false

         this.form.file = file.target.files
         console.log(this.form.file)
    }
}

Leave a comment