29 lines
783 B
PHP
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),
|
|
];
|
|
}
|
|
}
|