Laravel 5.1 - 未根据请求设置会话存储

I was trying to upgrade a Laravel 4.1 application to 5.1 on WAMP, and got this error:

RuntimeException in Request.php line 775: Session store not set on request.

in D:\wamp\www\laravel-5.1\vendor\laravel\framework\src\Illuminate\Http\Request.php line 775 at Request->session() in D:\wamp\www\laravel-5.1\vendor\laravel\framework\src\Illuminate\Foundation\Http\Middleware\VerifyCsrfToken.php line 137 at VerifyCsrfToken->addCookieToResponse(object(Request), object(Response)) in VerifyCsrfToken.php line 64 at VerifyCsrfToken->handle(object(Request), object(Closure)) at call_user_func_array(array(object(VerifyCsrfToken), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124 at Pipeline->Illuminate\Pipeline{closure}(object(Request)) at call_user_func(object(Closure), object(Request)) in Pipeline.php line 30 at Pipeline->Illuminate\Routing{closure}(object(Request)) at call_user_func(object(Closure), object(Request)) in Pipeline.php line 103 at Pipeline->then(object(Closure)) in ControllerDispatcher.php line 96 at ControllerDispatcher->callWithinStack(object(BrowseController), object(Route), object(Request), 'getBrowseRecent') in ControllerDispatcher.php line 54 at ControllerDispatcher->dispatch(object(Route), object(Request), 'App\Http\Controllers\BrowseController', 'getBrowseRecent') in Route.php line 174 at Route->runController(object(Request)) in Route.php line 140 at Route->run(object(Request)) in Router.php line 703 at Router->Illuminate\Routing{closure}(object(Request)) at call_user_func(object(Closure), object(Request)) in Pipeline.php line 139 at Pipeline->Illuminate\Pipeline{closure}(object(Request)) in ViewThrottleMiddleware.php line 55 at ViewThrottleMiddleware->handle(object(Request), object(Closure)) at call_user_func_array(array(object(ViewThrottleMiddleware), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124 at Pipeline->Illuminate\Pipeline{closure}(object(Request)) at call_user_func(object(Closure), object(Request)) in Pipeline.php line 30 at Pipeline->Illuminate\Routing{closure}(object(Request)) at call_user_func(object(Closure), object(Request)) in Pipeline.php line 103 at Pipeline->then(object(Closure)) in Router.php line 705 at Router->runRouteWithinStack(object(Route), object(Request)) in Router.php line 678 at Router->dispatchToRoute(object(Request)) in Router.php line 654 at Router->dispatch(object(Request)) in Kernel.php line 246 at Kernel->Illuminate\Foundation\Http{closure}(object(Request)) at call_user_func(object(Closure), object(Request)) in Pipeline.php line 139 at Pipeline->Illuminate\Pipeline{closure}(object(Request)) in CheckForMaintenanceMode.php line 44 at CheckForMaintenanceMode->handle(object(Request), object(Closure)) at call_user_func_array(array(object(CheckForMaintenanceMode), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124 at Pipeline->Illuminate\Pipeline{closure}(object(Request)) at call_user_func(object(Closure), object(Request)) in Pipeline.php line 103 at Pipeline->then(object(Closure)) in Kernel.php line 132 at Kernel->sendRequestThroughRouter(object(Request)) in Kernel.php line 99 at Kernel->handle(object(Request)) in index.php line 54

The storage folder is writable, and the session driver used is file. I searched the whole project for session(), but found it nowhere. What can I do to correct this error? Thanks!

The session.php is as follows:

<?php

return [
    'driver' => env('SESSION_DRIVER', 'file'),
    'lifetime' => 120,
    'expire_on_close' => false,
    'encrypt' => false,
    'files' => storage_path('framework/sessions'),
    'connection' => null,
    'table' => 'sessions',
    'lottery' => [2, 100],
    'cookie' => 'laravel_session',
    'path' => '/',
    'domain' => null,
    'secure' => false,

];

Edit 1: I found the problem is in the controller. There is a line:

$this->middleware('csrf', [ 'on' => 'post' ]);

I commented it out and it worked. But I didn't figure out why it caused the problem yet.

Look at @Cas Bloem his answer here this helped me out amazingly:

Laravel - Session store not set on request

That's why it wasn't working for me. Cause you're using a session that is expection matching CSRF tokens (is my best guess, I'm new to Laravel myself).

Also if you go to app->http->middleware->VerifyCsrfToken this is were you can add routes to the array that won't be checked for CSRF verification. This plus Cas Bloem his fix (place routes in different section in routes.php) fixed my problem. I'm just developing/learning on localhost right now but need to implement this later on.

Hope this helps/clears thing up!