We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

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 ?



58.4k

HI

You can use method beforeValidationOnCreate for Inster and beforeValidationOnUpdate for update