I am doing an Ajax login for my Laravel application.
I am using Angular:
$http({
method: 'POST',
url: '/admin/login',
headers: {
'Content-Type': 'application/json'
},
data: {email:$scope.email,password:$scope.password}
})
This request works fine, my problem is that Laravel's response always redirects me, as it should if I wasn't sending JSON:
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($errors);
}
That is the Laravel framework code. It keeps redirected me back, but I want to fire the conditional if ($request->expectsJson()) and get a JSON response rather than a redirect.
What am I missing in order to trigger that conditional?
from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2sHTPDS
via IFTTT
Aucun commentaire:
Enregistrer un commentaire