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, 'attachments' => $this->whenLoaded( 'attachments', fn () => PageAttachmentResource::collectionFor( $this->attachments, $this->preview ? 'admin' : 'public' ) ), 'created_at' => $this->created_at ? $this->formatDateTimeStringForUser($this->created_at) : null, 'updated_at' => $this->updated_at ? $this->formatDateTimeStringForUser($this->updated_at) : null, ]; } }