preview = $preview; return $this; } /** * 리소스를 배열로 변환합니다. * * @param Request $request HTTP 요청 객체 * @return array */ public function toArray(Request $request): array { $locale = app()->getLocale(); $fallback = config('app.fallback_locale', 'ko'); return [ 'id' => $this->id, 'slug' => $this->slug, 'title' => $this->getLocalizedTitle(), 'content' => is_array($this->content) ? ($this->content[$locale] ?? $this->content[$fallback] ?? (! empty($this->content) ? array_values($this->content)[0] : '')) : (string) ($this->content ?? ''), 'content_mode' => $this->content_mode ?? 'html', 'is_preview' => $this->preview, 'published_at' => $this->published_at ? $this->formatDateTimeStringForUser($this->published_at) : null, 'seo_meta' => $this->seo_meta, 'current_version' => $this->current_version, // 미발행 페이지는 pages.read 관리자의 미리보기(is_preview)로만 이 리소스에 // 도달하므로(공개 게이트가 게스트를 404 차단), 그 화면의 썸네일용으로 // 한시 서명 preview URL 을 직렬화한다. 발행 페이지는 무서명 공개 URL 유지. 'attachments' => $this->whenLoaded( 'attachments', fn () => PageAttachmentResource::collectionFor( $this->attachments, signedPreview: ! $this->published ) ), 'created_at' => $this->created_at ? $this->formatDateTimeStringForUser($this->created_at) : null, 'updated_at' => $this->updated_at ? $this->formatDateTimeStringForUser($this->updated_at) : null, ]; } }