I try to create login form with Ajax using Laravel 5.2 Auth.
$(document).ready(function(){$.ajaxSetup({ headers: {'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content') }});$('#login').on('click',function(e){e.preventDefault(); var formData = { email: $('#email').val(), password: $('#password').val(),} $.ajax({ type: "POST", url: "/login", data: formData, success: function (data) { location.reload(); }, error: function (data) { } });});})enter code here
Laravel default login function:
public function login(Request $request){$this->validateLogin($request);// If the class is using the ThrottlesLogins trait, we can automatically throttle// the login attempts for this application. We'll key this by the username and// the IP address of the client making these requests into this application.$throttles = $this->isUsingThrottlesLoginsTrait();if ($throttles && $lockedOut = $this->hasTooManyLoginAttempts($request)) { $this->fireLockoutEvent($request); return $this->sendLockoutResponse($request);}$credentials = $this->getCredentials($request);if (Auth::guard($this->getGuard())->attempt($credentials, $request->has('remember'))) { return $this->handleUserWasAuthenticated($request, $throttles);}// If the login attempt was unsuccessful we will increment the number of attempts// to login and redirect the user back to the login form. Of course, when this// user surpasses their maximum number of attempts they will get locked out.if ($throttles && ! $lockedOut) { $this->incrementLoginAttempts($request);}return $this->sendFailedLoginResponse($request);}
/login return index page as a response. I need json response about error messages or success message. It is said that changing Laravel core functions is not advisable. Then how can I get it?