关于Laravel如何管理会话,我需要一些帮助。 当我使用纯PHP进行编程时,我使用的是全局变量$ _SESSION。 这样,当我想检索有关用户的信息时,我通过$ _SESSION ['id']变量在数据库中找到用户。 我不明白Laravel如何使用它。 你能指导一些指南吗? 提前致谢。
I need some help regarding on how Laravel manages sessions. When I was programming with pure PHP, i was using the global variable $_SESSION. This way, when I wanted to retrieve information regarding an user, I was finding the user in the database by $_SESSION['id'] variable. I do not understand how Laravel works with this. Can you guide to some guides, please? Thanks in advance.
最满意答案
正如第一条评论所指出的那样,Laravel拥有自己的Session控制系统,可以通过使用Session Facade在应用程序的任何位置访问它。
要在会话中存储值,您可以
Session::put('key', 'value');要检索值:
$value = Session::get('key');As pointed in the first comment, Laravel has it's own Session controlling system, that can be accessed, at any point of your application, by using the Session facade.
To store a value in the session, you do
Session::put('key', 'value');To retrieve the value:
$value = Session::get('key');更多推荐
发布评论