eibersji
eibersji

Reputation: 1216

TokenMismatchException in VerifyCsrfToken.php line 68: Laravel 5.3

I have been looking for answers around the net for 3 hours now, and have tried so many solutions but it did not work. I have tried: answers from here

But none of them worked

Solution 1:

sudo rm -rf storage/framework/sessions/*
sudo php artisan cache:clear

Solution 2:

Clearing my cache and cookies in my browser, then running

php artisan config:cache and php artisan cache:clear

Solution no. 3

enter image description here

Solution no. 4

enter image description here

Solution no.5

I tried changing my {{ csrf_field() }} to {!! csrf_field() !!}

Solution no. 6

I tried moving Auth::routes(); on top of my web routes.

Solution no. 7

enter image description here

Solution no. 8

I have changed my code from:

 <form class="form-horizontal" role="form" method="POST" action="{{ url('/login') }}">
   {{ csrf_field() }}

to:

 <div class="panel-body">
    {!! Form::open([ 'route' => 'login', 
                     'method' => 'POST' ]) !!}

I even tried adding a {{ csrf_field() }} in Form::open

I even tried adding another bracket {{{ csrf_field() }}}

Solution no. 9

Desperately restarting my server(MAMP) then clearing cache

There is another solution, which says that I should download a fresh install of Laravel, but I cannot do that because this is a big project.


Here is my .env file

API_DEBUG=true
APP_ENV=local
APP_KEY=base64:g43UiAlu11L/y9ThUjiVqFi52/d2Jf/JHaPNwkwzU4o=
APP_DEBUG=true
APP_LOG_LEVEL=debug
APP_URL=http://127.0.0.1

BROADCAST_DRIVER=log
CACHE_DRIVER=file
SESSION_DRIVER=file
QUEUE_DRIVER=sync

SESSION_SECURE_COOKIE=true

REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379

PUSHER_APP_ID=
PUSHER_KEY=
PUSHER_SECRET=

API_PREFIX=api
API_SUBTYPE=app
API_VERSION=v1

JWT_TTL=20160

SIGN_UP_RELEASE_TOKEN=false
PASSWORD_RESET_RELEASE_TOKEN=false

PAGINATION_ITEMS_PER_PAGE=10

# Database Connections

DB_CONNECTION=mysql-core
DB_CORE_HOST=localhost:8889
DB_CORE_PORT=3306
DB_CORE_DATABASE=core
DB_CORE_USERNAME=root
DB_CORE_PASSWORD=root

my Kernel.php

class Kernel extends HttpKernel
{
protected $middleware = [
    \Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode::class,
];

/**
 * The application's route middleware groups.
 *
 * @var array
 */
protected $middlewareGroups = [
    'web' => [
        \App\Http\Middleware\EncryptCookies::class,
        \Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
        \Illuminate\Session\Middleware\StartSession::class,
        \Illuminate\View\Middleware\ShareErrorsFromSession::class,
        \App\Http\Middleware\VerifyCsrfToken::class,
        \Illuminate\Routing\Middleware\SubstituteBindings::class,
        'secure.requests',
    ],

in my session.php

'driver' => env('SESSION_DRIVER', 'file'),
'files' => storage_path('framework/sessions'),
'domain' => env('SESSION_DOMAIN', null),
'secure' => env('SESSION_SECURE_COOKIE', false),

Here's my web.php

<?php

Route::group([ 'middleware'  => [ 'secure.requests' ] ], function() {

    Auth::routes();

    Route::get('/', function () {
        return view('welcome');
    });

});

I am also using the laravel dubugbar enter image description here

It's a long post, but I am desperate to be able to solve this. I hope someone can help me.

EDIT: I tried logging in from the API side (locally) and it works. the problem is just the web side.

Upvotes: 2

Views: 2000

Answers (3)

jdubu423
jdubu423

Reputation: 425

I found these steps from here: token mismatch

1). Remove 'SESSION_DRIVER' field from your .env 2). Go to your config/session.php and in domain mark the second parameter of env() to null i.e.

'domain' => env('SESSION_DOMAIN', null)

3). Run php artisan cache:config and php artisan cache:clear 4). Restart the server and clear your browser cache, and whoaa may be all things are up and running now.

Upvotes: 1

user8824269
user8824269

Reputation:

Try this

{{ csrf_field() }} to

<input type="hidden" name="_token" class="_token" value="{{ csrf_token() }}">

Upvotes: 0

Ali Al-Estarbadee
Ali Al-Estarbadee

Reputation: 546

I have faced the same issue once, try to run the command below from the project directory:

chmod 777 storage/framework/sessions/

I hope it will work for you!

Upvotes: 0

Related Questions