My Code is below but it's not working. I can upload Image with base64 formate and successfully store on Laravel backend but I'm struggling to upload other file formates in Laravel and vue.js. Anyone can help please?
.vue file
<template>
<div>
<form enctype="multipart/form-data" @submit.prevent="handleSubmit">
<div class="form-group mb-4">
<label>Institute Prospectus</label>
<label class="custom-file-container__custom-file">
<input
type="file"
class="form-control-file"
@change="onChangeProspectus"
/>
</label>
</div>
</form>
</div>
</template>
<script>
export default {
data() {
return {
institute_prospectus: "",
};
},
methods: {
handleSubmit() {
let data = {
institute_prospectus: this.institute_prospectus,
};
axios.post(data, "/add-institute")
.then(() => {
console.log("Success");
})
.catch((err) => {
console.log(err);
});
},
onChangeProspectus(event) {
let file = event.target.files[0];
this.institute_prospectus = file.name;
},
},
};
</script>
InstituteController.php
public function add_institute(Request $request) {
$prospectus_file = $request->institute_prospectus;
if ($prospectus_file) {
$ext = substr($prospectus_file, strrpos($prospectus_file, '.', -1), strlen($prospectus_file));
$name = time().'-'.$slug.".".$ext;
$upload_path = 'backend/files/institute/';
$prospectus_url = $upload_path.$name;
$prospectus_file->move($upload_path,$prospectus_url);
}
}
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire