Laravel 5.2:如何从自定义登录事件处理程序调用“sendFailedLoginResponse”?

时间:2016-05-12 07:32:11

标签: login event-handling laravel-5.2

在Laravel 5.2中,我的AuthController.php中已经有一个覆盖功能:

public function sendFailedLoginResponse()
{
    $errors = new MessageBag([
                'email' => ['Error message for email'],
                'password' => ['Error message for password'],
                'mycustominput' => ['Error message for my custom input field'],
        ]);

    return redirect()->back()->withErrors($errors);
}

仅通过正常的FAILED登录尝试就可以运行(如魔术)。 (登录失败时,登录表单已经显示此自定义错误消息,而不是默认消息。所以这正在被触发。所以没关系。)

现在我在自定义登录事件处理程序下面,已注册EventServiceProvider.php

'Illuminate\Auth\Events\Login' => ['App\Listeners\UserLoggedIn']

然后,我想从这个自定义登录事件处理程序TRIGGER重写的函数sendFailedLoginResponse()。类似的东西:

app/Listeners/UserLoggedIn.php

// Some codes at top

public function handle(Login $event)
{
    // Some coding ..
    // Some custom verifications ..

    if ( $customLoginCheck == false ) 
    {
        ????::sendFailedLoginResponse(); // <----- Here call/trigger the method!
    }
}

当我尝试使用Auth::sendFailedLoginResponse()时,它会出现以下错误:

ErrorException in AuthManager.php line 288:
call_user_func_array() expects parameter 1 to be a valid callback, class 'Illuminate\Auth\SessionGuard' does not have a method 'sendFailedLoginResponse'

因为我不知道如何从自定义事件处理程序调用所需的函数。 (而且还不知道所需的内容包括哪些。)

请帮忙建议。 (全部谢谢)

0 个答案:

没有答案
相关问题