laravel 的会话刷新和忘记方法没有按预期工作

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/39857510/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 14:33:49  来源:igfitidea点击:

laravel's Session flush and forget methods not working as expected

phplaravelsession

提问by Mazino S Ukah

I tried to delete a value from my session using :

我尝试使用以下方法从我的会话中删除一个值:

Session::forget('value')

but it didn't delete!

但它没有删除!

However, when i tried using savemethod like so :

但是,当我尝试使用这样的save方法时:

 Session::forget('value')
 Session::save()

it worked! (I.e. the value was deleted from the session.)

有效!(即该值已从会话中删除。)

Please - what am I doing wrong? I don't see the savemethod in the Laravel documentation when using Session::flush()and Session::forget().

请 - 我做错了什么?save使用Session::flush()and时,我在 Laravel 文档中没有看到该方法Session::forget()

回答by Tschallacka

The save() method will actaully perform the write to the file.

save() 方法将实际执行对文件的写入。

It seems that your application doesn't call Session::save() before it outputs content to the user on all requests.

您的应用程序似乎在将所有请求的内容输出给用户之前没有调用 Session::save() 。

If this method isn't called, the Session file will not get updated with the new values, and they will still be there on the next visit.

如果未调用此方法,则会话文件将不会使用新值进行更新,并且下次访问时它们仍将存在。

It's important to always call Session::save() if you wish to be sure stuff got removed or added and the change persists.

如果您希望确保删除或添加内容并且更改仍然存在,请务必始终调用 Session::save()。

回答by Rizwan Saleem

Full cache clear (either using command-line or code):

完全清除缓存(使用命令行或代码):

php artisan cache:clear
Artisan::call('cache:clear');

+ Full session flush:

+ 完整会话刷新:

Session::flush();

through this method you can clear all of your session data.

通过这种方法,您可以清除所有会话数据。

回答by Rizwan Saleem

i use Session::save()method its work fine to save session data. But when i flush session using Session::flush()it does not clear all the data that is stored in Laravel session. Session::forget('value')works fine to clear session specific value.

我使用Session::save()其工作正常的方法来保存会话数据。但是,当我使用Session::flush()它刷新会话时,不会清除 Laravel 会话中存储的所有数据。Session::forget('value')可以很好地清除会话特定值。