2017-05-16 93 views
2

my laravel版本是5.3。我在laravel中使用內置身份驗證來登錄用戶。覆蓋登錄laravel身份驗證

在用戶表中有一個列名爲status。當它是0這意味着用戶無法登錄。

現在我不知道如何在登錄方法/用戶之前檢查此列。 我不希望用戶可以登錄時status列是0

回答

3

您可以覆蓋authenticated()功能:

protected function authenticated() 
    { 
     if (auth()->user()->status==0) { 
      auth()->logout(); 
      return redirect('/'); 
     } 
    } 

您還可以Manually authenticate users通過重寫authenticate()功能:

public function authenticate() 
    { 
     if (Auth::attempt(['email' => $email, 'password' => $password, 'status' => 1])) 
     { 
      // Authentication passed... 
      } 
    }