|
|
@@ -971,7 +971,7 @@ class Validator implements ArrayAccess, IteratorAggregate, Countable
|
|
|
* @param string|null $message The error message when the rule fails.
|
|
|
* @param string|callable|null $when Either 'create' or 'update' or a callable that returns
|
|
|
* true when the validation rule should be applied.
|
|
|
- * @see \Cake\Validation\Validation::compareWith()
|
|
|
+ * @see \Cake\Validation\Validation::compareFields()
|
|
|
* @return $this
|
|
|
*/
|
|
|
public function sameAs($field, $secondField, $message = null, $when = null)
|
|
|
@@ -979,7 +979,28 @@ class Validator implements ArrayAccess, IteratorAggregate, Countable
|
|
|
$extra = array_filter(['on' => $when, 'message' => $message]);
|
|
|
|
|
|
return $this->add($field, 'sameAs', $extra + [
|
|
|
- 'rule' => ['compareWith', $secondField]
|
|
|
+ 'rule' => ['compareFields', $secondField, true]
|
|
|
+ ]);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Add a rule to compare that two fields have different values.
|
|
|
+ *
|
|
|
+ * @param mixed $field The field you want to apply the rule to.
|
|
|
+ * @param mixed $secondField The field you want to compare against.
|
|
|
+ * @param string|null $message The error message when the rule fails.
|
|
|
+ * @param string|callable|null $when Either 'create' or 'update' or a callable that returns
|
|
|
+ * true when the validation rule should be applied.
|
|
|
+ * @see \Cake\Validation\Validation::compareFields()
|
|
|
+ * @return $this
|
|
|
+ * @since 3.6.0
|
|
|
+ */
|
|
|
+ public function notSameAs($field, $secondField, $message = null, $when = null)
|
|
|
+ {
|
|
|
+ $extra = array_filter(['on' => $when, 'message' => $message]);
|
|
|
+
|
|
|
+ return $this->add($field, 'notSameAs', $extra + [
|
|
|
+ 'rule' => ['compareFields', $secondField, false]
|
|
|
]);
|
|
|
}
|
|
|
|