Level 6
hi.
Here is my Vue method which I use to upload multiple files (I´m using loadash to loop through the files). You need to add "multiple" to your input field.
attachDocuments: function(e) {
this.fileNames = []
this.form.attachments = e.target.files || e.dataTransfer.files
_.forEach(this.form.attachments, (file) => {
this.fileNames.push(file.name)
if(file.size > 15728640) {
alert('Filen er for stor. Maks størrelse er 15MB!')
this.form.attachments = []
this.fileNames = []
}
})
this.submitForm()
},
submitForm() {
this.loading = true
this.form[this.method](this.action)
.then(response => {
this.loading = false
window.location.href = response.redirect
})
.catch(error => {
this.loading = false
if (error.response.status === 401) {
this.showmodal('image-auth-error')
}
this.displayErrorMessage(this.form.errors.all())
})
},
input
<input class="cursor-pointer absolute block opacity-0 pin-r pin-t" type="file" name="file" id="file" @change="attachDocuments" multiple accept='image/*'>