code: private function ensureOrder(Model $attachment, string $type): Model
      {
          $attachmentOrder = $attachment->get('order');
  
          if (empty($attachmentOrder)) {
              $attachment->set(
                  'order',
                  count($this->getAttachmentByField($type)) + 1
              );
          }
  
          return $attachment;
      }
docs: ensuring order