36 lines
1.1 KiB
PHP
36 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,
|
|
'thumbnail_url' => $this->resource->thumbnail_path ?? null,
|
|
'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')),
|
|
];
|
|
}
|
|
}
|