Laravel 5.2 : How to call “sendFailedLoginResponse” from custom Login Event Handler?

你。 提交于 2020-01-06 23:48:51

问题


In Laravel 5.2, there is a function already overriden in my 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);
}

This alone works (like magic) via normal FAILED login attempts. (When login is failed, the login form already shows this custom error messages, instead of the default ones. So this is getting triggered. So is ok.)


Now i have below Custom Login Event Handler, registered in the EventServiceProvider.php:

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

And then, i wanna TRIGGER the overridden function sendFailedLoginResponse() from this Custom Login Event Handler. Something like:

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!
    }
}

When i tried using Auth::sendFailedLoginResponse(), it gives me following errors:

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'

Because i do NOT know "how" to call that desired function from a Custom Event Handler. (And also don't know what are the required includes.)

Please help to suggest. (Thanks all)

来源:https://stackoverflow.com/questions/37180161/laravel-5-2-how-to-call-sendfailedloginresponse-from-custom-login-event-hand

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!