feat: introduce ProductCategoryResource and refactor database migrations by deleting old tables and consolidating transaction schema.

This commit is contained in:
pbao9
2026-02-18 21:44:31 +07:00
parent 9a2cab4521
commit 75791d6257
12 changed files with 76 additions and 163 deletions
@@ -3,6 +3,7 @@
namespace App\Http\Controllers\Api\Service;
use App\Http\Controllers\Controller;
use App\Http\Resources\Api\Service\ProductCategoryResource;
use App\Http\Resources\Api\Service\ServiceResource;
use App\Models\Product;
use App\Models\ProductCategories;
@@ -63,7 +64,7 @@ class ProductCategoryController extends Controller
return response()->json([
'error' => false,
'message' => 'Lấy dữ liệu thành công',
'data' => $categories,
'data' => ProductCategoryResource::collection($categories),
]);
}
@@ -0,0 +1,26 @@
<?php
namespace App\Http\Resources\Api\Service;
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' => $this->is_active,
'sort_order' => $this->sort_order,
'type' => $this->type,
'type_label' => $this->type_label,
'children' => $this->when($this->children, function () {
return self::collection($this->children);
}),
];
}
}