如何在laravel 5.x中检查用户的状态是否有效?

时间:2016-01-20 16:24:17

标签: php laravel laravel-authorization

我在laravel 5.2提供的AuthController中设置了一些不同的登录逻辑。代码是

 protected function authenticated(Request $request)
    {

        $email = $request->input('email');
        $password = $request->input('password');

        if (Auth::attempt(['email' => $email, 'password' => $password, 'is_active' => 1])) {
            return redirect()->intended('admin/dashboard');
        }

        return $this->sendFailedLoginResponse($request);
    }

代码工作正常。但是当用户不活动时,它仍然以用户身份登录。那么如何停止使用is_active = 0验证用户?

更新:用户迁移

Schema::create('users', function (Blueprint $table) {
    $table->increments('id');
    $table->string('name');
    $table->string('email')->unique();
    $table->string('password', 60);
    $table->tinyInteger('is_active', 0);
    $table->rememberToken();
    $table->timestamps();
});

1 个答案:

答案 0 :(得分:1)

这是正确的方法:http://laravel.io/forum/11-04-2014-laravel-5-how-do-i-create-a-custom-auth-in-laravel-5?page=1#reply-29759

您的方法无法正常工作,因为Laravel默认的Auth :: attempt不会检查is_active条件。