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
];
I had the same problem. When investigating, I discovered that at some point in my code, I used return
.
It turns out (as you can see in the end of the handle method) that after executing the handle method you should always call return $next($request);
.
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!
Well the addCookieToResponse method in the Illuminate\Session\Middleware\StartSession class is wanting a Response object as the first param. Make sure that you return one in all of your routes.
Here's a possible quick fix, change it to fit your case.
Before:
Route::get('hi', function() {
return 'hi';
});
After:
Route::get('hi', function() {
return response('hi');
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With