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

29 lines
783 B
PHP

<?php
namespace App\Http\Resources;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
/**
* @property \App\Models\Category $resource
*/
class CategoryResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @return array<string, mixed>
*/
public function toArray(Request $request): array
{
return [
'id' => $this->resource->id,
'parent_id' => $this->resource->parent_id,
'name' => $this->resource->name,
'slug' => $this->resource->slug,
'description' => $this->resource->description,
'products_count' => $this->when(isset($this->resource->products_count), (int) $this->resource->products_count),
];
}
}