Good morning, I'm trying to make a check if the cpf typed already exists in the bank, I'm using laravel, could anyone help me in this function please?
In my controller, I search and ready all cpfs of the bank:
$cpfduplicado = UsuarioEsic::lists('doc', 'id')->all();
foreach ($cpfduplicado as $cpf)
if ($cpf == $request->cpf)
$cpf = 'verdadeiro';
// return redirect('/Esic/CadastroFisica');
return redirect('/Esic/Sucesso');
I do not know very well how to do a function in javascript to get this data and set a custom validity of the browser, I did something like this:
$(function cpfdupli(input) {
$('.btnCadastroo').on('click', function (json){
if (json.cpf === 'verdadeiro'){
document.getElementById('cpff');
input.setCustomValidity('Cpf já existe.');
} else {
input.setCustomValidity('');
}
});
});
I'm a beginner in the branch and I'm not really sure how to make it work, I just wanted it if cpf already existed, put a CustomValidity in the browser and do not let it continue with the registration, if someone can help me or give me other Ways to solve this I would be very grateful!
Note: Any questions about the code will be available to provide.