I am trying to make a verification in ajax if an email has already been taken in laravel 5.
This is my ajax:
$.ajax({
type: 'POST',
url: '/EditEmail',
data: form.serialize(),
dataType: 'json',
timeout: 9000,
error:function(data) {
//verify if the user has already been taken
},
success:function(data) {
window.location.href=window.location.href;
}
});
This is the code in my controller :
public function EditEmail()
{
if(Hash::check(Input::get('ParolaActuala'),$parola) && count(User::where('email','=',$NoulEmail)->get()) == 0 )
{
DB::table('users')->where ('user_id',Auth::user()->user_id)->update(array('email' => Input::get('NoulEmail')));
return Response::json(['success' => 'request succeeded'], 200);
}
}
So i already make the verification in my controller and user can't introduce the same email but i want to know how can i send data from my controller to ajax so i can make the verification there too.Does anybody have a solution ?