I know that this is an issue largely discussed and I have read a lot of posts about this but cannot find a solution.
I have developed a site locally on my PC and everything runs beautifully. I then put the site on my personal site to see how it would function. Upon doing this everything seemed to work except the Authentication part of my site. When I try to log in to my application I receive this error TokenMismatchException in VerifyCsrfToken.php line 46
I did not get this error locally but receive it when it is on my host server. Is there something I missed? need to change in a config file?
I have updated my .env, app.php, database.php files to run with my personal site. I made sure that this <input type="hidden" name="_token" value="{{ csrf_token() }}">
element was right under my <form>
tag as seen from other posts with this similar problem.
Ideas?
HTML:
<form class="form-horizontal" role="form" method="POST" action="">
<input type="hidden" name="_token" value="{{ csrf_token() }}">
Try to perform the following:
php artisan key:generate
.env
file.If You are posting form using jquery then you should include csrf_token()
$_token = "{{ csrf_token() }}";
$.post( 'myurl', { param1: $param1, param2: $param2, _token: $_token })
.done(function( data )
{
console.log('Done!');
});
And if you are posting the form directly and facing the same problem then goto app/Http/Resquests/Kernel.php and comment this line
\App\Http\Middleware\VerifyCsrfToken::class
See this answer and avoid doing what suggested above all the time.