Why don't you dd(request()->all())?
I think the problem is you forgetting v-model
<input type="file" name="content" id="content" v-model="content">
I think it should fix the problem @dstrTop1
Form:
<form method="POST" v-on:submit.prevent="onSubmitForm" class="col-md-12"
enctype="multipart/form-data">
<input type="file" name="content" id="content">
<button type="submit" class="btn btn-success col-md-offset-10">Submit</button>
</form>
here is my vue code:
onSubmitForm: function(e){
e.preventDefault();
var diplom = this.newDiploma;
this.$http.post('/diplomas', diplom);
}
data:{
newDiploma:{
content:''
}
controller:
public function add(Request $request){
request()->file('content')->store('images');
}
what I get is: Call to a member function store() on null Seems like controller gets no inputs from form
As the error is telling you, you have to listen for a change in the input field.
<input type="file" name="content" id="content" @change="newAvatar">
Then make a method:
newAvatar(event) {
let files = event.target.files;
if (files.length) this.newDiploma.content = files[0];
}
Then you can post the request. I used axios but I couldn't send multipart/form-data so I had to use FormData Objects. Here is the code just in case.
postAvatar(){
let data = new FormData()
data.set('avatar', this.avatar)
axios.post('/profile/avatar', data)
.then(response => {
//Do stuff
})
.catch(error => console.log(error));
}
Hope this helps you. Cheers
Please or to participate in this conversation.