title: Laravel 5.1 - Session store not set on request
body: <p>I was trying to upgrade a Laravel 4.1 application to 5.1 on WAMP, and got this error:</p>
  
  <blockquote>
    <p>RuntimeException in Request.php line 775: Session store not set on
    request.</p>
    
    <p>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</p>
  </blockquote>
  
  <p>The <code>storage</code> folder is writable, and the session driver used is <code>file</code>. I searched the whole project for <code>session()</code>, but found it nowhere. What can I do to correct this error? Thanks!</p>
  
  <p>The <code>session.php</code> is as follows:</p>
  
  <pre><code>&lt;?php
  
  return [
      'driver' =&gt; env('SESSION_DRIVER', 'file'),
      'lifetime' =&gt; 120,
      'expire_on_close' =&gt; false,
      'encrypt' =&gt; false,
      'files' =&gt; storage_path('framework/sessions'),
      'connection' =&gt; null,
      'table' =&gt; 'sessions',
      'lottery' =&gt; [2, 100],
      'cookie' =&gt; 'laravel_session',
      'path' =&gt; '/',
      'domain' =&gt; null,
      'secure' =&gt; false,
  
  ];
  </code></pre>
  
  <p><strong>Edit 1</strong>: I found the problem is in the controller. There is a line:</p>
  
  <pre><code>$this-&gt;middleware('csrf', [ 'on' =&gt; 'post' ]);
  </code></pre>
  
  <p>I commented it out and it worked. But I didn't figure out why it caused the problem yet.</p>