Ad

How To Check If User's Status Is Active In Laravel 5.x?

- 1 answer

I have set a bit different login logic in AuthController provided by laravel 5.2. The code is

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

The code works fine. But the problem when user is not active, it still get logged in as users. So how do i stop authenticating users with is_active = 0?

UPDATE: User Migration

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();
});
Ad

Answer

this is the correct way to do it : http://laravel.io/forum/11-04-2014-laravel-5-how-do-i-create-a-custom-auth-in-laravel-5?page=1#reply-29759

Your method won't work because the Laravel default Auth::attempt will not check the is_active condition.

Ad
source: stackoverflow.com
Ad