id = $model->id; $instance->name = $model->name; $instance->order = $model->order; if ($model->external) { $instance->link = $model->path; } else { $instance->file = $files->referenceForAttachment($model); } return $instance; } public static function fromModelArray(array $attachmentArray, ZipExportFiles $files): array { return array_values(array_map(function (Attachment $attachment) use ($files) { return self::fromModel($attachment, $files); }, $attachmentArray)); } public static function validate(ZipValidationHelper $context, array $data): array { $rules = [ 'id' => ['nullable', 'int'], 'name' => ['required', 'string', 'min:1'], 'order' => ['nullable', 'integer'], 'link' => ['required_without:file', 'nullable', 'string'], 'file' => ['required_without:link', 'nullable', 'string', $context->fileReferenceRule()], ]; return $context->validateData($data, $rules); } }