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.

Dylan Wheeler
  • 6,928
  • 14
  • 56
  • 80
Jesse Walters
  • 71
  • 1
  • 5
  • when does this error come in? – Vishal Sharma Dec 24 '15 at 01:51
  • please show `sessions.php` config. And, are you following the documentations upgrade procedure? – Vishal Sharma Dec 24 '15 at 01:55
  • I checked the upgrade documentation, and tried to remove `'App\Http\Middleware\VerifyCsrfToken',` from `App\Http\Kernel`, but it didn't help. csrf still shows in `php artisan route:list` as middleware. Is this the reason? – Jesse Walters Dec 24 '15 at 02:02
  • https://laravel.com/docs/5.0/upgrade#upgrade-5.0 this link says that you will have to create another app with new framework dependency. And copy your 4.1 controllers route etc to the new app. – Vishal Sharma Dec 24 '15 at 02:05
  • Thanks @VishalSh . Please see my update. – Jesse Walters Dec 24 '15 at 02:17
  • It is not advisable to turn off csrf verification as it is a security feature. https://github.com/laravel/framework/issues/9632 there is a similar issue raised on laravel github. – Vishal Sharma Dec 24 '15 at 02:19
  • Possible duplicate of [Laravel - Session store not set on request](http://stackoverflow.com/questions/34449770/laravel-session-store-not-set-on-request) – Yoh Deadfall Dec 25 '15 at 19:43

1 Answers1

0

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!

Community
  • 1
  • 1
Kasper
  • 11
  • 3