*/ public function toArray(Request $request): array { $locale = $request->query(config('locales.query_parameter')) ?? app()->getLocale(); $resolved = TranslatablePayload::resolve($this->resource, $this->translatable, $locale); return [ 'id' => $this->id, 'locale' => $locale, ...$resolved, 'status' => $this->status->value, 'status_label' => $this->status->getLabel(), 'is_featured' => $this->is_featured, // The stored path, because this is the editing API and it is // what a client PATCHes back. What was *derived* from it travels // alongside rather than replacing it. 'featured_image' => $this->featured_image, 'featured_image_media' => ImagePayload::make( $this->featured_image, $this->resource->relationLoaded('featuredMedia') ? $this->resource->getRelation('featuredMedia') : null, $resolved['featured_image_alt'] ?? null, ), 'published_at' => $this->published_at?->toIso8601String(), 'unpublish_at' => $this->unpublish_at?->toIso8601String(), 'created_at' => $this->created_at?->toIso8601String(), 'updated_at' => $this->updated_at?->toIso8601String(), 'deleted_at' => $this->deleted_at?->toIso8601String(), 'category' => CategoryResource::make($this->whenLoaded('category')), 'author' => UserResource::make($this->whenLoaded('author')), // Opt-in: `?with=translations` returns every language at once, // which is what a translation UI needs and a page renderer does not. 'translations' => $this->when( in_array('translations', explode(',', (string) $request->query('with')), true), fn () => TranslatablePayload::all($this->resource, $this->translatable), ), ]; } }