Sprawdź duplikat e -mail za pomocą sprawdzania poprawności JQuery
//html form
<form id="formId" method="post" action="url">
@csrf
<input type="email" id="email" name="email">
<button type="submit">Submit</button>
</form>
//jquery validation to check Duplicate Emails
//Dont't forget to include jqury and jquery.validation files or CDN
<script>
$("#FormId").validate({
rules:{
email: {
required: true,
email:true,
remote: 'check-duplicate-email'
}
},
messages: {
email: {
required: "Email is required",
email: "Valid Email Please",
remote: "This Email Already Exists"
}
}
});
<script>
//Route
Route::match(['get', 'post'], 'check-duplicate-email', [ControllerName::class, 'checkDuplicateEmail']);
//controller function
public function checkDuplicateEmail(Request $request){
if($request->ajax()){
$adminEmail = $request->email;
$emailCount = ModelName::where('email', $adminEmail)->count();
if($emailCount>0){
echo "false";
} else {
echo "true";
}
}
}
Isaac