/**
  * @param RelationInfo $info
  * @param string       $attribute   key of attribute
  * @param null|int     $index       if data is plural for this attribute, the index for it
  * @return array
  */
 protected function getNestedRelationValidationRulesForSingleItem(RelationInfo $info, $attribute, $index = null)
 {
     $rules = [];
     $dotKey = $attribute . (null !== $index ? '.' . (int) $index : '');
     $data = array_get($this->data, $dotKey);
     // if the data is scalar, it is treated as the primary key in a link-only operation, which should be allowed
     // if the relation is allowed in nesting at all -- if the data is null, it should be considered a detach
     // operation, which is allowed aswell.
     if (is_scalar($data) || null === $data) {
         // add rule if we know that the primary key should be an integer
         if ($info->model()->getIncrementing()) {
             $rules[$this->getNestedKeyPrefix() . $dotKey] = 'integer';
         }
         return $rules;
     }
     // if not a scalar or null, the only other value allowed is an array
     $rules[$this->getNestedKeyPrefix() . $dotKey] = 'array';
     $keyName = $info->model()->getKeyName();
     $keyIsRequired = false;
     $keyMustExist = false;
     // if it is a link-only or update-only nested relation, require a primary key field
     // it also helps to check whether the key actually exists, to prevent problems with
     // a non-existant non-incrementing keys, which would be interpreted as a create action
     if (!$info->isCreateAllowed()) {
         $keyIsRequired = true;
         $keyMustExist = true;
     } elseif (!$info->model()->getIncrementing()) {
         // if create is allowed, then the primary key is only required for non-incrementing key models,
         // for which it should always be present
         $keyIsRequired = true;
     }
     // if the primary key is not present, this is a create operation, so we must apply the model's create rules
     // otherwise, it's an update operation -- if the model is non-incrementing, however, the create/update
     // distinction depends on whether the given key exists
     if ($info->model()->getIncrementing()) {
         $creating = !array_has($data, $keyName);
     } else {
         $key = array_get($data, $keyName);
         $creating = !$key || !$this->checkModelExistsByLookupAtribute($key, $keyName, get_class($info->model()));
     }
     if (!$creating) {
         $keyMustExist = true;
     }
     // build up rules for primary key
     $keyRules = [];
     if ($info->model()->getIncrementing()) {
         $keyRules[] = 'integer';
     }
     if ($keyIsRequired) {
         $keyRules[] = 'required';
     }
     if ($keyMustExist) {
         $keyRules[] = 'exists:' . $info->model()->getTable() . ',' . $keyName;
     }
     if (count($keyRules)) {
         $rules[$this->getNestedKeyPrefix() . $dotKey . '.' . $keyName] = $keyRules;
     }
     // get and merge rules for model fields by deferring to a nested validator
     /** @var NestedValidatorInterface $validator */
     $validator = $this->makeNestedParser($info->validator(), [get_class($info->model()), $attribute, $this->appendNestedKey($attribute, $index), $this->model, $this->config, $this->modelClass]);
     $rules = $this->mergeInherentRulesWithCustomModelRules($rules, $validator->validationRules($data, $creating));
     return $rules;
 }