-2
I am building an update form. I want that when the user requests an email exchange, first I check that the email is no longer in use. In my html form I have the following field:
<div class="col-4">
<label for="" class="form-control-label">E-mail:</label>
<input type="text" name="email" id="email" class="form-control" value="{{Auth::user()->email}}">
</div>
In my controller I use the following code to check if the email already exists:
public function perfil(Request $request)
{
$usuarioEmail = User::where('email', '=', $request->input('email'))->first();
if ($usuarioEmail) {
if($usuarioEmail->email != Auth::user()->email) //Se o email já estiver cadastrado no banco, verifico se pertence ao usuário que está solicitando a troca
//Email já utilizado por outro usuário
}//Se o email não estiver em uso, troco normalmente
else{User::where('userId', Auth::user()->userId)->update(['email' => $request->input('email')]);}
}
I would like to do this verification in real time without updating the page. How to proceed?
Without updating the page is always JS with ajax
– Isac
That’s what @Isac said, only with Ajax
– Alisson Hoepers