ErrorException in StartSession.php line 175
ErrorException in StartSession.php line 175:
Argument 1 passed to Illuminate\Session\Middleware\StartSession::addCookieToResponse() must be an instance of Symfony\Component\HttpFoundation\Response, string given, called in /usr/html/lumen/vendor/illuminate/session/Middleware/StartSession.php on line 72 and defined
in StartSession.php line 175
at Application->Laravel\Lumen{closure}('4096', 'Argument 1 passed to Illuminate\Session\Middleware\StartSession::addCookieToResponse() must be an instance of Symfony\Component\HttpFoundation\Response, string given, called in /usr/html/lumen/vendor/illuminate/session/Middleware/StartSession.php on line 72 and defined', '/usr/html/lumen/vendor/illuminate/session/Middleware/StartSession.php', '175', array()) in StartSession.php line 175
at StartSession->addCookieToResponse('<html> <head> <title>Lumen</title> <link href='//fonts.googleapis.com/css?family=Lato:100' rel='stylesheet' type='text/css'> <style> body { margin: 0; padding: 0; width: 100%; height: 100%; color: #B0BEC5; display: table; font-weight: 100; font-family: 'Lato'; } .container { text-align: center; display: table-cell; vertical-align: middle; } .content { text-align: center; display: inline-block; } .title { font-size: 96px; margin-bottom: 40px; } .quote { font-size: 24px; } </style> </head> <body> <div class="container"> <div class="content"> <div class="title">Lumen.</div> </div> </div> </body> </html> ', object(Store)) in StartSession.php line 72
at StartSession->handle(object(Request), object(Closure)) in Pipeline.php line 125
at Pipeline->Illuminate\Pipeline{closure}(object(Request)) in AddQueuedCookiesToResponse.php line 36
at AddQueuedCookiesToResponse->handle(object(Request), object(Closure)) in Pipeline.php line 125
at Pipeline->Illuminate\Pipeline{closure}(object(Request)) in EncryptCookies.php line 40
at EncryptCookies->handle(object(Request), object(Closure)) in Pipeline.php line 125
at Pipeline->Illuminate\Pipeline{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 101
at Pipeline->then(object(Closure)) in Application.php line 1317
at Application->sendThroughPipeline(array('Illuminate\Cookie\Middleware\EncryptCookies', 'Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse', 'Illuminate\Session\Middleware\StartSession', 'Illuminate\View\Middleware\ShareErrorsFromSession'), object(Closure)) in Application.php line 1099
at Application->dispatch(null) in Application.php line 1037
at Application->run() in index.php line 28
Lumen 首页,
$app->get('/', function() use ($app) {
return $app->welcome();
});
这段代码这两天报这个错, 刚开始安装好 Lumen 的时候还是很正常的, 不知道怎么了, 有人知道吗?
Argument 1 passed to Illuminate\Session\Middleware\StartSession::addCookieToResponse() must be an instance of Symfony\Component\HttpFoundation\Response, string given, called in /usr/html/lumen/vendor/illuminate/session/Middleware/StartSession.php on line 72 and defined
in StartSession.php line 175
at Application->Laravel\Lumen{closure}('4096', 'Argument 1 passed to Illuminate\Session\Middleware\StartSession::addCookieToResponse() must be an instance of Symfony\Component\HttpFoundation\Response, string given, called in /usr/html/lumen/vendor/illuminate/session/Middleware/StartSession.php on line 72 and defined', '/usr/html/lumen/vendor/illuminate/session/Middleware/StartSession.php', '175', array()) in StartSession.php line 175
at StartSession->addCookieToResponse('<html> <head> <title>Lumen</title> <link href='//fonts.googleapis.com/css?family=Lato:100' rel='stylesheet' type='text/css'> <style> body { margin: 0; padding: 0; width: 100%; height: 100%; color: #B0BEC5; display: table; font-weight: 100; font-family: 'Lato'; } .container { text-align: center; display: table-cell; vertical-align: middle; } .content { text-align: center; display: inline-block; } .title { font-size: 96px; margin-bottom: 40px; } .quote { font-size: 24px; } </style> </head> <body> <div class="container"> <div class="content"> <div class="title">Lumen.</div> </div> </div> </body> </html> ', object(Store)) in StartSession.php line 72
at StartSession->handle(object(Request), object(Closure)) in Pipeline.php line 125
at Pipeline->Illuminate\Pipeline{closure}(object(Request)) in AddQueuedCookiesToResponse.php line 36
at AddQueuedCookiesToResponse->handle(object(Request), object(Closure)) in Pipeline.php line 125
at Pipeline->Illuminate\Pipeline{closure}(object(Request)) in EncryptCookies.php line 40
at EncryptCookies->handle(object(Request), object(Closure)) in Pipeline.php line 125
at Pipeline->Illuminate\Pipeline{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 101
at Pipeline->then(object(Closure)) in Application.php line 1317
at Application->sendThroughPipeline(array('Illuminate\Cookie\Middleware\EncryptCookies', 'Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse', 'Illuminate\Session\Middleware\StartSession', 'Illuminate\View\Middleware\ShareErrorsFromSession'), object(Closure)) in Application.php line 1099
at Application->dispatch(null) in Application.php line 1037
at Application->run() in index.php line 28
Lumen 首页,
$app->get('/', function() use ($app) {
return $app->welcome();
});
这段代码这两天报这个错, 刚开始安装好 Lumen 的时候还是很正常的, 不知道怎么了, 有人知道吗?
3 个回复
NowAnti
赞同来自: Ditto
Lumen开启StartSession中间件后,报错:Response需要为Object,但是得到的是String
DStrider
赞同来自:
需要去bootstrap/app.php把$app->middleware反注解,同时反注解里面的'Illuminate\Session\Middleware\StartSession',
说实话如果这个错都找不出来那还是不要用lumen了。lumen对新上手laravel的人来说是个几百米的坑。
Ditto
赞同来自:
你好,
app.php 里已经是这样了:
$app->middleware([
'Illuminate\Cookie\Middleware\EncryptCookies',
'Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse',
'Illuminate\Session\Middleware\StartSession',
'Illuminate\View\Middleware\ShareErrorsFromSession',
//'Laravel\Lumen\Http\Middleware\VerifyCsrfToken',
]);
// $app->routeMiddleware([
// ]);
最下面两行是注释的, 没起效, 'Laravel\Lumen\Http\Middleware\VerifyCsrfToken', 这行也是因为有错被我注释了。