How to let the model's validator separately verify it in insert and update?

<?php
use Phalcon\Mvc\Model\Validator\Uniqueness as Uniqueness;
class Subscriptors extends Phalcon\Mvc\Model
{
  public function validation()
  {
      $this->validate(new Uniqueness(array(
          'field' => 'email'
      )));
      if ($this->validationHasFailed() == true) {
          return false;
      }
  }
}

This validation is working in insert and update. But I want to separate it. How can I do it ?



34.6k

HI

You can use method beforeValidationOnCreate for Inster and beforeValidationOnUpdate for update