在我的本地系统上一切正常,但在我们的测试系统上部署Laravel 5.2后,它看起来像是会话中间件坏了。有人可以帮忙吗?
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
全球中间件:
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
];
我有同样的问题。在调查时,我发现在我的代码中的某些时候,我使用了return
。
事实证明(正如你在handle方法的最后看到的那样)在执行handle方法之后你应该总是调用return $next($request);
。
那么Illuminate \ Session \ Middleware \ StartSession类中的addCookieToResponse方法需要一个Response对象作为第一个参数。确保在所有路线中都返回一个。
这是一个可能的快速修复,更改它以适合您的情况。
之前:
Route::get('hi', function() {
return 'hi';
});
后:
Route::get('hi', function() {
return response('hi');
});
就我而言,它只是缓存。试试跑步
php artisan config:cache