*/ public static function keys(): array { return [ 'category_public_id' => PublicKey::subselect('categories', 'slug', 'products.category_id'), ]; } /** * Transform the resource into an array. * * @return array */ public function toArray(Request $request): array { return [ 'id' => $this->slug, 'category_id' => PublicKey::value($this->resource, 'category_public_id', 'categories', 'slug', $this->category_id), 'name' => $this->name, 'sku' => $this->sku, 'status' => $this->status->value, 'price' => $this->price, 'compare_at_price' => $this->compare_at_price, 'photos' => collect($this->photos ?? [])->map(fn (string $p) => route('api.public.products.file', ['product' => $this->slug, 'column' => 'photos', 'path' => $p]))->all(), 'photos_variants' => collect($this->photos ?? [])->map(fn (string $p) => ImageVariants::urls('api.public.products.file', ['product' => $this->slug, 'column' => 'photos', 'path' => $p], Product::IMAGE_VARIANTS['photos']))->all(), 'video_url' => $this->video_url, 'description' => $this->description, 'size_chart' => $this->size_chart ? route('api.public.products.file', ['product' => $this->slug, 'column' => 'size_chart']) : null, 'is_featured' => $this->is_featured, 'published_at' => $this->published_at?->toIso8601String(), 'specs' => $this->specs === null ? null : (object) $this->specs, 'category' => $this->whenLoaded('category', fn () => PublicApi::one($this->category)), 'productVariants' => $this->whenLoaded('productVariants', fn () => PublicApi::many($this->productVariants)), 'reviews' => $this->whenLoaded('reviews', fn () => PublicApi::many($this->reviews)), 'coupons' => $this->whenLoaded('coupons', fn () => PublicApi::many($this->coupons)), 'tags' => $this->whenLoaded('tags', fn () => PublicApi::many($this->tags)), ]; } }