How to specify a validation rule in Yii2 that will be greater or less than a certain number or value?

I have a model with a validation rule, for example:

[['x'], 'integer'], [['x'], 'unique'], 

Now, how to add a rule like:

x <100
or something like x> = 100

+5
source share
1 answer

It should be:

 ['x', 'compare', 'compareValue' => 100, 'operator' => '<'], 

and

 ['x', 'compare', 'compareValue' => 100, 'operator' => '>='], 

respectively.

More details in official documents .

+5
source

Source: https://habr.com/ru/post/1216506/


All Articles