- Scenario
$scenarios['sell'] = [ 'deposit'];
- Rule
['deposit', 'required', 'on' => 'sell',
'message' => 'Deposit cannot be blank',
'when' => function () {
if (Yii::$app->controller->id == 'transaction' && $this->deposite_date != null) {
return true;
}
}
]
I want to validate the deposit field only in transaction controller and I pass any value in the deposit_date field. otherwise I don't want to validate the deposit field. but the validation happens in other controller as well.