feat: Implement full CRUD API for product categories and products, including recursive product counts for categories.

This commit is contained in:
pbao9
2026-03-06 11:15:26 +07:00
parent cca4e0b86f
commit cb8510cf56
5 changed files with 302 additions and 1 deletions
@@ -0,0 +1,30 @@
<?php
namespace App\Http\Resources\Api\Admin;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
class ProductCategoryResource extends JsonResource
{
public function toArray(Request $request): array
{
return [
'id' => $this->id,
'name' => $this->name,
'slug' => $this->slug,
'parent_id' => $this->parent_id,
'is_active' => (bool) $this->is_active,
'sort_order' => $this->sort_order,
'type' => $this->type,
'type_label' => $this->type_label,
'created_at' => $this->created_at?->toISOString(),
'children' => $this->whenLoaded('children', fn () =>
self::collection($this->children)
),
'products_count' => $this->whenCounted('products', fn () =>
$this->recursive_products_count
),
];
}
}