Skip to main content

How to add new rule in laravel validations in Laravel 8?

Add new rules in laravel validations in Laravel 8

//Rule

use Illuminate\Validation\Rule;   


      $validator = Validator::make($request->all(), [

            'email' => 'required|unique:users|max:255|email:rfc,dns',

'username' => [

'required','min:4',

Rule::unique('users')->where(function ($query) {

$query->where('is_verified','=', '1');

return $query;

})

],

            'displayname' => 'required',

            'password' => 'required',

        ],$messages = [], [

            'email' => 'Email',

            'username' => 'Username',

            'displayname' => 'Display Name',

            'password' => 'Password',

        ]);

Comments

Popular posts from this blog

How to check date format in PHP?

Check date format in PHP function isCorrectDateFromat($date){     if(!empty($date)){         $dateString = $date; // Replace this with your date string         $format = "Y-m-d"; // Replace this with your expected date format         $dateTime = DateTime::createFromFormat($format, $dateString);         if ($dateTime === false) { /*             echo "The date is not in the correct format."; */         } else {             $errors = DateTime::getLastErrors();             if (empty($errors)) { /*                 echo "The date is in the correct format."; */                 return true;             } else { /*                 echo "...