Conditional validation

Hi, in my Model I need a conditional validation. Now I use the following:

      ->requirePresence('iban', 'create', 'update')
      ->add('iban', [
      'length' => [
      'rule' => ['minlength', 22],
      'message' => 'Die IBAN muss 22 Zeichen lang sein!',

The iban needs to be 22 characters. But now I have add the condition:
Only if field ‘payer’ is set to 1, which is the field before iban.

I have tried this:
$validator->allowEmpty(‘iban’, function ($context) {
return $context[‘data’][‘payer’] === 0;

and receive an error: Undefinde index payer

How do I proceed?

in $context['data'] are only data you pass to validation i.e. when you do $this->patchEntity($user, $this->request->data) only $this->request->data is there. If you need to pass also original object data you can pass it as provider:

See this: Conditional application rules

If you have not many statuses for player (0 or 1)
You can make it easy:
if ($this->request->data[‘ControllerName’]['player] != 1) {