使用 Laravel 的会话数据库
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/26166662/
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
Using Laravel's Session Database
提问by Darryl Chapman
I'm trying to store details about each persons session in the database as shown here: http://laravel.com/docs/4.2/session#database-sessions, and now I have the table migrated and looking all good to go. However, I cannot actually find any documents that give help on how to use this table. I wish to track the last actions of each person and also count the people online.
我正在尝试将每个人会话的详细信息存储在数据库中,如下所示:http: //laravel.com/docs/4.2/session#database-sessions,现在我已经迁移了表并且看起来一切顺利。但是,我实际上找不到任何提供有关如何使用此表的帮助的文档。我希望跟踪每个人的最后行动,并计算在线人数。
Can anyone provide examples of usage of the session database, or links to documentation? I assumed that this table would be automatically managed by Laravel, but it appears I am incorrect.
任何人都可以提供会话数据库的使用示例或文档链接吗?我假设这个表会由 Laravel 自动管理,但看起来我是不正确的。
回答by Alan Storm
Can anyone provide examples of usage of the session database, or links to documentation? I assumed that this table would be automatically managed by Laravel, but it appears I am incorrect.
任何人都可以提供会话数据库的使用示例或文档链接吗?我假设这个表会由 Laravel 自动管理,但看起来我是不正确的。
The only thing incorrect is your assumption of being incorrect. The session database is a storage enginefor Laravel's session system. Once you've setup the database and configured Laravel to use the session database, you can use the syntax in the session docsto save and get data that's associated with each individual user of your web based system.
唯一不正确的是你的假设是不正确的。会话数据库是Laravel 会话系统的存储引擎。一旦您设置了数据库并将 Laravel 配置为使用会话数据库,您就可以使用会话文档中的语法来保存和获取与基于 Web 的系统的每个用户相关联的数据。
So, you have step 1 -- your database table created.
所以,您已经完成了第 1 步——创建了您的数据库表。
Step 2 would be configuring the storage engineby editing
第 2 步将通过编辑配置存储引擎
app/config/session.php
and changing this
并改变这一点
'driver' => 'file',
into this
进入这个
'driver' => 'database'
Once you've done that any call to the session's put
method (or other "saving data" methods) will store data in this table.
完成此操作后,对会话put
方法(或其他“保存数据”方法)的任何调用都将在此表中存储数据。