I have this form where the user should only type text inside a text area:
Automatic Axios CSRF token attaching Solution:
first, store the token in an HTML meta tag:
Then register the CSRF Token as a common header with Axios so that all outgoing HTTP requests automatically have it attached.
Inside your bootstrapping/main JS file, include:
let token = document.head.querySelector('meta[name="csrf-token"]');
if (token) {
window.axios.defaults.headers.common['X-CSRF-TOKEN'] = token.content;
} else {
console.error('CSRF token not found: https://laravel.com/docs/csrf#csrf-x-csrf-token');
}
Now you can make requests with csrf attached.