[['shortcode'],'string', 'length' => [8, 11]],// first
['shortcode','required', // second
'when' => function($model) {
// code here
},
],
How can I combined my rules length
only on if I set it to required
? Thanks in advance.
For now, Im always ending up checking for min length.
Best option (and it should always be used) is to use scenarios. I don't know any other solution to this, only with scenarios. In case you haven't used it yet, here's how you implement:
When you declare scenario
scenario_shortcode_only
, only those rules with'on' => 'scenario_shortcode_only'
will be validated while others will be ignored.