Laravel会话表添加额外的列 [英] Laravel session table add additional column

查看:57
本文介绍了Laravel会话表添加额外的列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在session表上添加一个额外的列user_id.

I want to add an extra column user_id on session table.

原因是,有时会有垃圾邮件发送者注册假帐户,一旦我知道用户是垃圾邮件发送者,我想通过删除会话记录来注销用户.

The reason is, some time there are spammer to sign up fake account, once I know that the user is spammer, I want to log the user out by deleting the session record.

有可能实现这一目标吗?

Is it possible to achieve this?

推荐答案

这是会话迁移模式:

Schema::create('sessions', function($table)
{
    $table->string('id')->unique();
    $table->text('payload');
    $table->integer('last_activity');
    $table->integer('user_id')->unsigned(); //// ADD IT!
});

您可以在其中添加任何所需的列,Laravel不在乎.

You can add whatever column you like on it, Laravel won't mind.

或者您可以创建一个新的迁移,并使其在该表上添加一列.

Or you can create a new migration and make it add a column on that table.

$table->integer('user_id')->unsigned();

您可以为其创建模型:

class SessionModel extends Eloquent {

}

然后用它做任何您需要的事情:

And do whatever you need with it:

$session = SessionModel::find(Session::getId());
$session->user_id = 1;
$session->save();

但是,如果您正在考虑向有效负载中添加更多信息,这是Laravel保留会话数据的位置,尽管我认为这是可能的,但您必须在Laravel的代码中进行更多的挖掘.

But if you're thinking about adding more info to the payload, which is where Laravel keeps the session data, although I think it's possible, you'll have to dig a bit more in Laravel's code to do that.

这篇关于Laravel会话表添加额外的列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆