feat: implement product and attachment management service with supporting migrations and API controllers
This commit is contained in:
@@ -23,6 +23,9 @@ class ProductResource extends JsonResource
|
||||
'nombre' => $this->nombre,
|
||||
'descripcion' => $this->descripcion,
|
||||
'precio' => $this->precio,
|
||||
'images' => $this->whenLoaded('attachments', fn () =>
|
||||
$this->attachments->map(fn ($attachment) => $attachment->getTemporaryUrl(1440))->values()
|
||||
),
|
||||
'variants' => ProductVariantResource::collection($this->whenLoaded('variants')),
|
||||
'created_at' => $this->created_at,
|
||||
'updated_at' => $this->updated_at,
|
||||
|
||||
@@ -25,9 +25,21 @@ class ProductVariantResource extends JsonResource
|
||||
'precio' => $this->precio,
|
||||
'product' => ProductResource::make($this->whenLoaded('product')),
|
||||
'definitions' => ProductVariantDefinitionResource::collection($this->whenLoaded('definitions')),
|
||||
'images' => $this->whenLoaded('attachments', fn () =>
|
||||
$this->attachments->map(fn ($attachment) => $attachment->getTemporaryUrl(1440))->values()
|
||||
),
|
||||
'images' => $this->whenLoaded('attachments', function () {
|
||||
if ($this->attachments->isNotEmpty()) {
|
||||
return $this->attachments
|
||||
->map(fn ($attachment) => $attachment->getTemporaryUrl(1440))
|
||||
->values();
|
||||
}
|
||||
|
||||
// Fallback: use product-level attachments when the variant has none
|
||||
$this->loadMissing('product.attachments');
|
||||
|
||||
return $this->product?->attachments
|
||||
?->map(fn ($attachment) => $attachment->getTemporaryUrl(1440))
|
||||
?->values()
|
||||
?? collect();
|
||||
}),
|
||||
'created_at' => $this->created_at,
|
||||
'updated_at' => $this->updated_at,
|
||||
];
|
||||
|
||||
Reference in New Issue
Block a user