*/ public function toArray(Request $request): array { $locale = app()->getLocale(); return [ 'id' => $this->id, 'locale' => $locale, /* * An explicit list rather than the model's whole translatable * set. `featured_image_alt` is in that set, and resolving it here * put the alt text at the top level as well as inside * `featured_image`, where the specification says it lives and * where an needs it. Two names for one string is how a * frontend ends up reading the one that later turns out to be the * accidental one. */ ...TranslatablePayload::resolve( $this->resource, ['title', 'slug', 'excerpt', 'body', 'meta_title', 'meta_description'], $locale, ), 'status' => $this->status->value, 'is_featured' => $this->is_featured, 'featured_image' => ImagePayload::make( $this->featured_image, $this->resource->relationLoaded('featuredMedia') ? $this->resource->getRelation('featuredMedia') : null, $this->getTranslation('featured_image_alt', $locale, false) ?: null, ), 'published_at' => $this->published_at?->toIso8601String(), // So a cache downstream can expire when the content does, rather // than holding a notice that is no longer true. 'unpublish_at' => $this->unpublish_at?->toIso8601String(), 'updated_at' => $this->updated_at?->toIso8601String(), 'category' => PublicCategoryResource::make($this->whenLoaded('category')), // Lets the frontend emit correct hreflang tags. Only locales that // actually have a translation appear. 'alternates' => SiteUrls::alternates($this->resource, 'page'), 'path' => SiteUrls::alternates($this->resource, 'page')[$locale] ?? null, ]; } }