diff --git a/src/Illuminate/Foundation/Auth/AuthenticatesUsers.php b/src/Illuminate/Foundation/Auth/AuthenticatesUsers.php index 15d92db26850..77b97bbf16b8 100644 --- a/src/Illuminate/Foundation/Auth/AuthenticatesUsers.php +++ b/src/Illuminate/Foundation/Auth/AuthenticatesUsers.php @@ -123,11 +123,15 @@ protected function authenticated(Request $request, $user) */ protected function sendFailedLoginResponse(Request $request) { + $errors = [$this->username() => trans('auth.failed')]; + + if ($request->expectsJson()) { + return response()->json($errors, 422); + } + return redirect()->back() ->withInput($request->only($this->username(), 'remember')) - ->withErrors([ - $this->username() => trans('auth.failed'), - ]); + ->withErrors($errors); } /** diff --git a/src/Illuminate/Foundation/Auth/ThrottlesLogins.php b/src/Illuminate/Foundation/Auth/ThrottlesLogins.php index c75c0ff57285..0f39a7e295b4 100644 --- a/src/Illuminate/Foundation/Auth/ThrottlesLogins.php +++ b/src/Illuminate/Foundation/Auth/ThrottlesLogins.php @@ -48,9 +48,15 @@ protected function sendLockoutResponse(Request $request) $message = Lang::get('auth.throttle', ['seconds' => $seconds]); + $errors = [$this->username() => $message]; + + if ($request->expectsJson()) { + return response()->json($errors, 423); + } + return redirect()->back() ->withInput($request->only($this->username(), 'remember')) - ->withErrors([$this->username() => $message]); + ->withErrors($errors); } /**