使用额外字段laravel 5.2手动验证用户

时间:2018-12-06 03:40:59

标签: laravel-5.2

我想实现这种额外的字段认证

public function authenticate(Request $request){
        $this->validate($request, [
              'username' => 'required|username', 'password' => 'required',
        ]);
       $credentials = $this->getCredentials($request);
      // This section is the only change
      if (Auth::validate($credentials)) {
          $user = Auth::getLastAttempted();
          if ($user->is_active == 'Y') {
              Auth::login($user, $request->has('remember'));
              return redirect()->intended($this->redirectPath());
          } else {
             return redirect($this->loginPath()) // Change this to redirect elsewhee
            ->withInput($request->only('username', 'remember'))
            ->withErrors([
                'active' => 'Please active your account'
              ]);
          }
      }
       return redirect($this->loginPath())
          ->withInput($request->only('username', 'remember'))
          ->withErrors([
              'username' => $this->getFailedLoginMessage(),
       ]);
      }

可能is_active列正在接受字符串is_active ='Y'

0 个答案:

没有答案