1
0
Fork 0
BitHarbor/backend/app/Http/Resources/ProductResource.php
2026-04-07 23:21:40 +02:00

35 lines
1.1 KiB
PHP

<?php
namespace App\Http\Resources;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
/**
* @property \App\Models\Product $resource
*/
class ProductResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @return array<string, mixed>
*/
public function toArray(Request $request): array
{
return [
'id' => $this->resource->id,
'name' => $this->resource->name,
'slug' => $this->resource->slug,
'sku' => $this->resource->sku,
'short_description' => $this->resource->short_description,
'description' => $this->resource->description,
'price' => $this->resource->price,
'stock_quantity' => $this->resource->stock_quantity,
'active' => $this->resource->active,
'published_at' => $this->resource->published_at,
'category' => CategoryResource::make($this->whenLoaded('category')),
'brand' => BrandResource::make($this->whenLoaded('brand')),
];
}
}