Laravel + Vue.js (axios) - CSRF token mismatch
Stefan Bogdanescu
Founder & Senior Architect · 2026-06-29
Title: Troubleshooting Laravel + Vue.js (axios) CSRF Token Mismatch Issue
Body:
When developing web applications with Laravel and Vue.js, you may encounter the occasional "CSRF token mismatch" error when making a POST request via axios. This issue occurs specifically when using Axios with Laravel's default CSRF protection. Thankfully, it is relatively easy to tackle this problem through understanding the causes and applying some simple solutions.
Understanding the Cause
The "CSRF token mismatch" issue usually arises due to either a missing or incorrectly set CSRF token in the request header. In Laravel, the CSRF (Cross-site Request Forgery) token is used to help prevent CSRF attacks by ensuring that only authenticated users have access to sensitive data and functionality through your application. Laravel provides an excellent protection layer for CSRF tokens via its built-in middleware in Kernel.php.Best Practices
To avoid the "CSRF token mismatch" issue, make sure to follow these best practices:- Ensure that you have included
@csrfon your form or used the Laravel Resource Controller for resourceful routes. This will automatically include the CSRF token in the HTML form. - Include a meta tag containing the CSRF token in App.blade.php and bootstrap.js file, as shown earlier in this post.
- Always set up middleware protection in your Kernel.php to ensure that only authenticated users can access your application's critical routes. This will help maintain CSRF token consistency.