I am handling image upload in laravel and vuejs.
In controller:
public function store(Request $request)
{
$data = $request->file;
return response()->json($data);
}
In vuejs :
data() {
return: {
file:null
}
},
methods: {
uploadFile() {
axios
.post("/promotion-platform/api/upload/store", {
file: this.file,
})
.then((res) => {
console.log(res.data);
//result :
{file: {…}}
file:
$path: null
__proto__: Object
__proto__: Object
//
})
.catch((error) => {
console.log(error);
});
},
},
Template:
<b-form @submit.prevent="uploadFile">
<b-form-file
v-model="file"
placeholder="Choose image..."
/>
</b-form>
When I select an image, and press submit, console.log(res.data)
returns empty, how do I get that image in the controller? Please give me ideas