Sessions not persisting in Lumen PHP framework

十年热恋 提交于 2019-12-04 04:05:12

Since you are trying to use the cookie session storage you'll need the cookie middleware too. The enabled middleware should be:

$app->middleware([
    'Illuminate\Cookie\Middleware\EncryptCookies',
    'Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse',
    'Illuminate\Session\Middleware\StartSession',
    'Illuminate\View\Middleware\ShareErrorsFromSession',
]);

In your first example you use the session immediately after creating it so you are able to recover the value. However, since the session cookie itself is not set by the code, when you return to the page, no session is recovered. The "laravel_session" cookie is always set whether you use cookie storage or not. I'm using the file storage in a project and still it gets set.

Also, AFAIK, the line:

$request->session()->save();

is unnecessary.


The documentation states:

To enable sessions, you must uncomment all of the middleware within the $app->middleware() method call in your bootstrap/app.php file.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!