使用laravel 4我正在尝试添加' active'列到我的数据库以检查用户是否处于活动状态且未被挂起,这是我的迁移用户表。
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";
}
答案 0 :(得分:1)
你可以按照你提到的方式进行,但Laravel的方法存在
if (Auth::attempt(array('email' => $email, 'password' => $password, 'active' => 1)))
{
// The user is active, not suspended, and exists.
}
阅读:Laravel\Docs\Authentication
只是我的2位:不建议你建立数据库的方式。您应该在email
表中保留用户登录信息(password
,active
和users
),并将其他人保存在单独的user_profile
表中。稍后您可以使用eloquent to map relations。