Search
 
SCRIPT & CODE EXAMPLE
 

PHP

Check duplicate email in laravel using jQuery validation

//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";
            }
        }
    }
Comment

PREVIOUS NEXT
Code Example
Php :: disable register laravel 
Php :: laravel grouping routes 
Php :: carbon set locale laravel 
Php :: Command "route:scan" is not defined. 
Php :: how to add property to the request object in laravel 
Php :: sort array by key value in php 
Php :: make model controller in single command 
Php :: nova resource title function 
Php :: windows wsl php 8 
Php :: allert in php 
Php :: calculate time difference php 
Php :: php configuration 
Php :: php ip 
Php :: yii2 confirm 
Php :: laravel eloquent order by alphabetical order 
Php :: laravel increment column value in update query 
Php :: upgrade php 7.3 centos 7 
Php :: laravel get parameters from request 
Php :: how check if variable is resgister in laravel 
Php :: Uncaught Error: Call to undefined function "themeblvd_add_builder_element()" 
Php :: php number format spaces 
Php :: AppHttpControllersValidator not found 
Php :: PHP strrchr — Find the last occurrence of a character in a string 
Php :: php code to check if variable is null 
Php :: rtl file manager laravel 
Php :: check php version mac 
Php :: alert a php variable 
Php :: php divide string into parts 
Php :: get php to send email from form 
Php :: php substr remove last 4 characters 
ADD CONTENT
Topic
Content
Source link
Name
5+2 =