Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

asdasdsa's avatar

Token mismatch vue resources

Hi! Im receiving a TokenMismatchException in VerifyCsrfToken.php line 68: when trying to perform a AJAX request with vue-resources. The odd is that the interceptor is there. Using Vue v2.0.3, Laravel 5.3.21, Vue resources ^1.0.3

dev-tools

vue-resource.common.js?2f13:1071 POST http://localhost:8000/posts 500 (Internal Server Error)

my form.vue

    export default {
        data() {
            return {
                body: null,
                title: null
            }
        },
        methods: {
            post() {
                this.$http.post('/posts', {
                    body: this.body,
                    title: this.title
                }).then((response) => {
                    // success
                    this.body = null;
                }, (response) => {
                    // error
                    console.log('error')
                });
            }
        }
    }

bootstrap.js

Vue.http.interceptors.push((request, next) => {
    request.headers['X-CSRF-TOKEN'] = Laravel.csrfToken;

    next();
});
0 likes
4 replies
willvincent's avatar

Use chrome dev tools and look on the network tab, for the ajax request, verify whether or not it's sending the X-CSRF-TOKEN header at all. That'd be the first step to track down the issue.

kfirba's avatar

@Johan66 hey.

Make sure that you add the route to your api.php file and not web.php

1 like
asdasdsa's avatar

Thanks everybody! I found the solution

Please or to participate in this conversation.