-1

Created a UsersTable.php file by baking from my database.

I have the user name working as an email address just fine.

But then I wanted to ensure that new users weren't trying to create an account with an existing email address. I found this pretty simple validator method in the docs, which looks to be exactly what I need.

    $validator
        ->email('email')
        ->requirePresence('email', 'create')
        ->allowEmptyString('email', false)
        ->validateUnique('email', true);

However... I get:

Call to undefined method Cake\Validation\Validator::validateUnique()
Randy Hall
  • 7,716
  • 16
  • 73
  • 151

1 Answers1

3

validateUnique is a method on the Table object, not the Validator object. You need to use the Validator::add method as shown in the examples on the page to which you linked.

Chris White
  • 1,068
  • 6
  • 11