post request using axios on Laravel 5.5
This is happening because of the csrf-token. Just add meta tag with the csrf-token in the <head>
and add that token to axios header like so.
// in the <head><meta name="csrf-token" content="{{ csrf_token() }}"><script type="text/javascript"> // For adding the token to axios header (add this only one time). var token = document.head.querySelector('meta[name="csrf-token"]'); window.axios.defaults.headers.common['X-CSRF-TOKEN'] = token.content; // send contact form data. axios.post('/post-contact',{name:'Kamal Abounaim' }).then((response)=>{ console.log(response) }).catch((error)=>{ console.log(error.response.data) });</script>
A 419 error seems to be Authentification Timeout. Your code looks fine to me, so it seems the error is with the post-contact
endpoint? Try testing that endpoint alone, in a tool like postman.