Laravel Session Middleware broken

Viewed 16401

On my local system everything works fine, but after deploying Laravel 5.2 on our test system it looks like the session middleware is broken. Can someone help here?

Argument 1 passed to Illuminate\Session\Middleware\    
StartSession::addCookieToResponse() must be an instance of  
Symfony\Component\HttpFoundation\Response, boolean given, called in   
... /httpdocs/service/vendor/laravel/framework/src/Illuminate/Session 
/Middleware/StartSession.php on line 72 and defined

The global middlewares:

protected $middleware = [
    \Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode::class,
    \Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
    \Illuminate\Session\Middleware\StartSession::class,
    \Illuminate\View\Middleware\ShareErrorsFromSession::class,
    \App\Http\Middleware\CORSMiddleware::class,
    \LucaDegasperi\OAuth2Server\Middleware\OAuthExceptionHandlerMiddleware::class
];
6 Answers

I had similar problem in one of mine middleware (v5.8). 'Call to a member function SetCookie() on null', 'Add the CSRF token to the response cookies'

This was my code, working fine in 5.2, but failed in Laravel 5.8:

return view('pages.my_page')->with('data', $data);

changed to:

return response()->view('pages.my_page', ['data' => $data]);

Cheers!

In my case it was just cache. try running

php artisan config:cache

To all the people coming for this error, it's the cookie that fails.

  1. So the fastest fix is to use another browser.

  2. Go to settings in your browser and find the cookie and delete it.

I had the same issue, turned out the issue for me was I changed the domain in my config/session.php in my production server


    'domain' => env('SESSION_DOMAIN', 'mydomain.com'),

on my development server which use 127.0.0.1 can't access my domain

change it to


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

and now working fine

Related