• Unique field validation in cake php 3.8 Model

  • Back
 by 

The main validation in CakePHP is done in models and you can modify as per required.

use Cake\ORM\RulesChecker;
public function validationDefault(Validator $validator)
{
        $validator->requirePresence('login_id');
	return $validator;
}

public function buildRules(RulesChecker $rules)
{
   $rules->add($rules->isUnique(['login_id'],'User already exist.'));
   return $rules;  
}

Leave your comment

Your email address will not be published. Required fields are marked *