code: protected function fillRelated(
          $record,
          ResourceObject $resource,
          EncodingParametersInterface $parameters
      ) {
          $relationships = $resource->getRelationships();
          $changed = false;
  
          foreach ($relationships as $field => $value) {
              /** Skip any fields that are not fillable. */
              if ($this->isNotFillable($field, $record)) {
                  continue;
              }
  
              /** Skip any fields that are not relations */
              if (!$this->isRelation($field)) {
                  continue;
              }
  
              $relation = $this->getRelated($field);
  
              if ($this->requiresPrimaryRecordPersistence($relation)) {
                  $relation->update($record, $value, $parameters);
                  $changed = true;
              }
          }
  
          /** If there are changes, we need to refresh the model in-case the relationship has been cached. */
          if ($changed) {
              $record->refresh();
          }
      }
docs: Hydrate related models after the primary record has been persisted.
  
  @param Model $record
  @param ResourceObject $resource
  @param EncodingParametersInterface $parameters