Php 如何在guard()中获取特定错误->;Laravel 5中的尝试方法

Php 如何在guard()中获取特定错误->;Laravel 5中的尝试方法,php,laravel,Php,Laravel,我尝试在Laravel框架中创建自己的身份验证逻辑 在我的LoginController中,我使用以下登录方法: public function login(Request $request) { if ($this->hasTooManyLoginAttempts($request)) { $this->fireLockoutEvent($request); return (ErrorsResponse::ha

我尝试在Laravel框架中创建自己的身份验证逻辑

在我的LoginController中,我使用以下登录方法:

    public function login(Request $request) {
        if ($this->hasTooManyLoginAttempts($request)) {
            $this->fireLockoutEvent($request);
            return (ErrorsResponse::haveErrors([ 'common' => 'Слишком много попыток входа' ]));
        }
        $try_validate = $this->validator($request->all())->errors();
        if ($try_validate->messages()) {
            return (ErrorsResponse::haveErrors($try_validate->messages()));
        }

        $auth_data = [
            'username' => $request->username,
            'password' => Hash::make($request->password),
        ];

        if ($this->attemptLogin($auth_data, $request->filled('remember'))) {
            $request->session()->regenerate();
            $this->clearLoginAttempts($request);
            return $this->authenticated($request, $this->guard()->user())
                    ?: redirect()->intended($this->redirectPath());
        }

        // Attemp fail
        $this->incrementLoginAttempts($request);
        return (ErrorsResponse::haveErrors([ 'common' => 'Ошибка авторизации' ]));
    }

但是standart
attemptLogin
只返回
false
true
值,而我希望收到关于“为什么失败”的完整信息


有没有一种方法可以在不编写我自己的
guard()->trunt
的情况下获取特定错误?

那么您想要这些错误?比如说“这封邮件没有注册”,比如@AlbertoSinigaglia yep,类似这样的。到目前为止,我唯一能想到的是:首先尝试通过用户名找到用户,类似这样:$user\u try\u to\u login=user::where('username',$request->username)->first();如果(!$user\u try\u to\u login){return(ErrorsResponse::haveErrors(['username'=>['user not found']]);}使用
$this->sendFailedLoginResponse($request)检查您从AuthenticatesUsers特征中获得的sendFailedLoginResponse方法,可能从它返回的内容可以得到错误message@AlbertoSinigaglia不,它只返回redirect=(那么您想要错误?比如“此电子邮件未注册”例如?@AlbertoSinigaglia yep,类似这样的。到目前为止,我唯一能想到的是:首先尝试通过用户名查找用户,类似这样的:$user\u try\u to\u login=user::where('username',$request->username)->first();if(!$user\u try\u to\u login){返回(ErrorsResponse::haveErrors(['username'=>['user not found]])}使用
$this->sendFailedLoginResponse($request);
检查AuthenticateUsers特性中的sendFailedLoginResponse方法;,可能从它返回的内容可以得到错误message@AlbertoSinigaglia不,它只是返回重定向=(