1
votes

In Cakephp 3 Model>Table I want to add Validation rule for enum type field in Cakephp 3 validationDefault method.I did cake-bake the Modal and got the default validation for field 'status' which is enum type in MySql. $validator->allowEmpty('status'); I want enum validations here so that given values are allowed for 'status' field. E.g. ENUM('Pass','Fail').

1

1 Answers

1
votes

Try using inList https://api.cakephp.org/3.6/class-Cake.Validation.Validator.html#_inList

$validator
    ->scalar('status')
    ->inList('status', ['Pass','Fail'])
    ->allowEmpty('status');