렌더 가능한 * 한시 서명 URL 로 직렬화하기 위한 플래그다. */ private ?string $signedPreviewSlug = null; /** * 첨부파일 목록을 리소스 배열로 변환합니다. * * @param iterable|null $attachments 첨부파일 목록 * @param string|null $signedPreviewSlug 서명 preview URL 발급 대상 슬러그 (비밀글·삭제글 전용) * @return array */ public static function collectionFor($attachments, ?string $signedPreviewSlug = null): array { return Collection::make($attachments ?? []) ->map(function ($attachment) use ($signedPreviewSlug) { $resource = new self($attachment); $resource->signedPreviewSlug = $signedPreviewSlug; return $resource; }) ->values() ->all(); } /** * 리소스를 배열로 변환합니다. * * @param Request $request HTTP 요청 * @return array 변환된 배열 데이터 */ public function toArray(Request $request): array { return [ 'id' => $this->id, 'hash' => $this->hash, 'original_filename' => $this->original_filename, 'mime_type' => $this->mime_type, 'size' => $this->size, 'size_formatted' => $this->size_formatted, 'collection' => $this->collection, 'order' => $this->order, 'download_url' => $this->download_url, 'preview_url' => $this->signedPreviewSlug !== null && $this->resource->is_image ? $this->resource->previewUrlForSlug($this->signedPreviewSlug, signed: true) : $this->preview_url, 'is_image' => $this->is_image, 'meta' => $this->meta, ]; } }