I've been struggling with this error for months now and I've tried everything but it just won't work. So here's the situation: I'm currently making a web app using Laravel. In my backoffice I work with blade and in my front I work with vue.js. Now in the backoffice with blade everything works perfectly without any issues. But in the front, when I tried to POST or PUT anything I constantly got the error: TokenMismatchException in VerifyCsrfToken.php line 68. now I know that with Laravel you have to pass a token when posting ANYTHING. So I've tried EVERYTHING. (I'm going to list all the things I've already tried). So eventually I discovered that you could just turn off the token verification by removing the line:
\App\Http\Middleware\VerifyCsrfToken::class,
from my kernel.php. After I did that everything worked and I decided to build my website without VerifyCsrfToken. But eventually, after working months on this project, I got an error that Laravel didn't recognise an online user in the frond office (Auth::id() returned null while I did log in a user in the backoffice). And suddenly I came to realise that you actually need VerifyCsrfToken for laravel to know that a user is online (it gave this error: {error: "Unauthenticated."}". So my problem now is that I have to implement the VerifyCsrfToken verify in order to make my application work. But I've literally tried everything and I still keep getting the same error with every POST and PUT I do:
"TokenMismatchException in VerifyCsrfToken.php line 68"
So these are the things that I've tried implementing:
(in the vue template)
<script>
window.Laravel = {
csrfToken: ''
}
</script>
(also in the vue template)
this.$http.interceptors.push((request, next) => {
request.headers.set('X-CSRF-TOKEN', window.Laravel.csrfToken)
})
( also in the vue template)
<script>
var csrf = '';
</script>
(in my main.js script)
var formData = new FormData();
formData.append('_token', csrf);
formData.append('input', this.newUserVoted);
this.$http.post('http://www.nmdad2-05-elector.local/api/v1/electionuser', formData)
(in my main index.html)
<html>
<head>
<meta charset="utf-8">
<meta name="csrf-token" content="">
<title>Elector</title>
(in the script of my index.html file)
<script>
window.Laravel = {
csrfToken: ''
}
</script>
and I've probably tried loads of other things. If someone could actually help me fix this you'd be my hero! My deadline is in one week and I'm starting to stress out a little bit.
via hxwtch