i want to display json errors returned from controller in ajax success function i am getting errors like
{"message":"The given data was invalid.","errors":{"user_phone":["The user phone must be a number."],"user_email":["The user email must be a valid email address."]}}
i want to display those errors on specific input if not, just give me a solution so that i will get every input error in a variable like var email = [//all errors related to email];
please ask me any inputs you want from my side
these is my ajax code
$.ajax({
url: "register/submit",
type: "post",
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
},
data: {'user_firstname':user_firstname,'user_lastname':user_lastname,'user_phone':user_phone,'user_email':user_email,'user_username':user_username,'password':user_password,'password_confirmation':user_password_confirmation},
success: function(result){
console.log(result);
}
});
}
here is my controller code
public function submit(Request $request)
{
Validator::make($request->all(), [
'user_firstname' => 'required|string|max:255',
'user_lastname' => 'required|string|max:255',
'user_phone' => 'required|numeric|max:15|unique:users,user_phone',
'user_email' => 'required|email|unique:users,email',
'user_username' => 'required|string|max:255|unique:users,username',
'password' => 'required|string|min:6|confirmed',
'password_confirmation' => 'min:6|same:password',
])->validate();
}
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire