Im new to vue in laravel. earlier when I want to save some data throw an action below form I can use {{ csrf_field() }}
How can I do that when using axios.post,
In my console it will give a error
CSRF token not found:
I know because I didnt defined that can someone tell me how to do that
my app.js file like below
require('./bootstrap');
window.Vue = require('vue');
var Vue = require('vue');
Vue.use(require('vue-resource'));
Vue.component('example', require('./components/Example.vue'));
const app = new Vue({
el: '#new',
data: {
message: 'Update New Post:',
content: '',
},
methods:{
addPost(){
axios.post('/addPost', {
content: this.content
})
.then(function(response) {
console.log(response);
})
.catch(function(error) {
console.log(error);
});
}
}
});
and my home.blade file like below
<div id="new">
<form class="form-horizontal" role="form" enctype="multipart/form-data" method="POST" v-on:submit.prevent="addPost">
{{ csrf_field() }}
<h4>@{{message}}</h4>
<div class="form-group" style="padding:14px;">
<textarea v-model="content" class="form-control" placeholder="Update your status"></textarea><br>
<button class="btn btn-primary pull-right" type="submit">Post</button>
</div>
</form>
</div>
data will added to database but it gives an error like csrf token not found