dongshi2458 2014-04-10 21:23
浏览 119

laravel检查用户是否处于活动状态?

using laravel 4 I am trying to add 'active' column to my database to check if the user is active and is not suspended , here is my migration users table.

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');
}

could you help me if I use $table->boolean('active'); // check this one

*is this the right way to do it? so I can use the Auth class like this to check if the user is active or not? *

$is_active = Auth::user()->active;

if (!$is_active == 1)
   {
echo "Account not activated";
   }
  • 写回答

1条回答 默认 最新

  • dsgsgs30201 2014-04-10 23:49
    关注

    You can do it the way you have mentioned but the Laravel way to do this exists

    if (Auth::attempt(array('email' => $email, 'password' => $password, 'active' => 1)))
    {
        // The user is active, not suspended, and exists.
    }
    

    Read : Laravel\Docs\Authentication

    Just my 2 bit : The way are building you database is not advised. You should keep your user login information (email, password & active) in users table and others in a separate user_profile table. Later you can use eloquent to map relations.

    评论

报告相同问题?

悬赏问题

  • ¥15 vscode问题请教
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM