dimanche 29 novembre 2015

Laravel 5.1: $errors->all() like response via ajax

Laravel 5.1: When a user is authenticated via regular POST request, an array of all validation errors can be accessed via method $errors->all(). However when a user is authenticated via Ajax request, that property is not available in the returned object. How can I make Validator to return error messages with $errors->all() or in the same structure when authenticating via Ajax request?

public function postLogin(Request $request)
{
    $this->validate($request, [
            $this->loginUsername() => 'required', 'password' => 'required',
        ]);

    $credentials = $this->getCredentials($request);

    if (Auth::attempt($credentials, $request->has('remember'))) {
        return $this->handleUserWasAuthenticated($request, $throttles);
    }
}



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire