问题
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