@ajsmith_codes see if adding a crsf token helps here
Aug 7, 2020
25
Level 5
401 Unauthorized when trying to update through Axios.
Laravel 7, Vue, Bootstrap-vue, Coreui Laravel admin template, Spatie Auth.
I can get data via Axios, but can't seem to post.
In my vue component:
updateUser() {
console.log('Editing data');
this.form.put('api/user/' + this.form.id)
.then(() => {
$('#addNew').modal('hide');
$emit('AfterCreate');
})
.catch(() => {
this.$Progress.fail();
});
},
URL in the PUT is: 127.0.0.1:8000/api/user/1
API Route file: Route::apiResources(['user' => 'API\UserController']);
Level 25
@ajsmith_codes I'm sorry, just read your entire reply.
In this case, then you should pass it as an object:
updateUser(e, user) {
console.log('Editing data');
if (this.name) {
axios.patch('/user/' + this.form.id + '/update',
{ name: this.form.name, email: this.form.email }
)
.then((response) => {
$('#success').html(response.data.message)
$('#addNew').modal('hide');
window.location.reload()
})
.catch(error => {
console.log(error)
});
}
},
Please or to participate in this conversation.