【发布时间】:2014-05-24 19:46:01
【问题描述】:
使用 laravel 4 我正在尝试将“活动”列添加到我的数据库中以检查用户是否处于活动状态且未挂起,这是我的迁移用户表。
public function up()
{
//
Schema::create(
'users',
function (Blueprint $table) {
$table->increments('id');
$table->string('email', 300);
$table->string('password', 60);
$table->boolean('active'); // check this one
$table->string('first_name', 100);
$table->string('last_name', 100);
$table->string('address', 250)->nullable();
$table->string('city', 100)->nullable();
$table->string('state', 2)->nullable();
$table->string('zip', 5)->nullable();
$table->string('phone', 10)->nullable();
$table->timestamps();
}
);
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
//
Schema::drop('users');
}
如果我使用 $table->boolean('active'); 你能帮我吗? // 检查这个
*这是正确的做法吗?所以我可以使用这样的 Auth 类来检查用户是否处于活动状态? *
$is_active = Auth::user()->active;
if (!$is_active == 1)
{
echo "Account not activated";
}
【问题讨论】:
-
除了将其命名为“活动”而不是“激活”之外,没关系。如果您想添加一个字段,告诉您用户不活跃(禁用或其他),它会更容易阅读。
-
但是 laravel 如何读取它是“活动的”或“激活的”,或者 laravel 会知道它并不重要?
-
或者你的意思是如果我让它'激活'然后检查: Auth::user()->activated; ?
-
我的意思是,如果您想要激活字段(例如单击的电子邮件链接)和激活字段(即未禁用/暂停),它对您来说更具可读性,对于 laravel 没有区别。当然,您在 user() 上调用它就像您在表中命名它一样:)
-
这对我来说是正确的。你遇到了什么问题?