Search code examples
phplaravelcsrflaravel-5.3

Laravel 5.3 - TokenMissmatchException in VerifyCsrfToken.php


I have a problem that my login page in Laravel. When I run my project php artisan serve I have successfully logged in localhost:8000/login.

However, if I call localhost/project/login I get a TokenMismatchException in VerifyCsrfToken.php.

My login form looks like this.

<head>
    <meta name="csrf-token" content="{{ csrf_token() }}">
    ...
</head>

<body>
    <form method="post" action="{{ url('/login') }}">
        {!! csrf_field() !!}
        ...
    </form>
</body>

How can I fix that? Thanks.


Solution

  • I answered the question myself again. I hope this helps someone. The thing that causes the problem was Session. The problem was solved by changing config driver from file to database.

    Edit:

    php artisan session:table
    
    php artisan migrate
    

    .env file set to:

    SESSION_DRIVER=database
    

    I could not fix the issue when I set the session driver to file. There was probably a problem with permission. I didn't put much effort. I did this and it was fixed.