Clean up documentation and infrastructure configuration files, and refine API resources and controllers for products and services.

This commit is contained in:
pbao9
2026-03-09 14:18:04 +07:00
parent 7b3c955d38
commit 80a5e0ca3d
13 changed files with 390 additions and 2656 deletions
@@ -53,27 +53,36 @@ class ProductController extends Controller
public function store(Request $request): JsonResponse
{
$validated = $request->validate([
'name' => 'required|string|max:255',
'product_type' => 'nullable|string',
'category' => 'nullable|string|max:255',
'is_active' => 'boolean',
'setup_fee' => 'nullable|numeric|min:0',
'cpu' => 'nullable|numeric|min:0',
'ram' => 'nullable|numeric|min:0',
'disk' => 'nullable|numeric|min:0',
'bandwidth' => 'nullable|numeric|min:0',
'name' => 'required|string|max:255',
'product_categories_id' => 'nullable|integer|exists:product_categories,id',
'product_type' => 'nullable|string',
'category' => 'nullable|string|max:255',
'is_active' => 'boolean',
'setup_fee' => 'nullable|numeric|min:0',
'cpu' => 'nullable|numeric|min:0',
'ram' => 'nullable|numeric|min:0',
'disk' => 'nullable|numeric|min:0',
'bandwidth' => 'nullable|numeric|min:0',
]);
$productType = $validated['product_type'] ?? null;
if (!$productType && !empty($validated['product_categories_id'])) {
$category = \App\Models\ProductCategories::find($validated['product_categories_id']);
$productType = $category?->type;
}
$product = Product::create([
'name' => $validated['name'],
'slug' => Str::slug($validated['name']),
'product_type' => $validated['product_type'] ?? null,
'is_active' => $validated['is_active'] ?? true,
'setup_fee' => $validated['setup_fee'] ?? 0,
'cpu' => $validated['cpu'] ?? null,
'ram' => $validated['ram'] ?? null,
'disk' => $validated['disk'] ?? null,
'bandwidth' => $validated['bandwidth'] ?? null,
'name' => $validated['name'],
'slug' => Str::slug($validated['name']),
'product_categories_id' => $validated['product_categories_id'] ?? null,
'product_type' => $productType,
'is_active' => $validated['is_active'] ?? true,
'setup_fee' => $validated['setup_fee'] ?? 0,
'cpu' => $validated['cpu'] ?? null,
'ram' => $validated['ram'] ?? null,
'disk' => $validated['disk'] ?? null,
'bandwidth' => $validated['bandwidth'] ?? null,
]);
return response()->json([
@@ -92,20 +101,26 @@ class ProductController extends Controller
}
$validated = $request->validate([
'name' => 'sometimes|required|string|max:255',
'product_type' => 'nullable|string',
'is_active' => 'boolean',
'setup_fee' => 'nullable|numeric|min:0',
'cpu' => 'nullable|numeric|min:0',
'ram' => 'nullable|numeric|min:0',
'disk' => 'nullable|numeric|min:0',
'bandwidth' => 'nullable|numeric|min:0',
'name' => 'sometimes|required|string|max:255',
'product_categories_id' => 'nullable|integer|exists:product_categories,id',
'product_type' => 'nullable|string',
'is_active' => 'boolean',
'setup_fee' => 'nullable|numeric|min:0',
'cpu' => 'nullable|numeric|min:0',
'ram' => 'nullable|numeric|min:0',
'disk' => 'nullable|numeric|min:0',
'bandwidth' => 'nullable|numeric|min:0',
]);
if (isset($validated['name']) && $validated['name'] !== $product->name) {
$validated['slug'] = Str::slug($validated['name']);
}
if (empty($validated['product_type']) && !empty($validated['product_categories_id'])) {
$category = \App\Models\ProductCategories::find($validated['product_categories_id']);
$validated['product_type'] = $category?->type;
}
$product->update($validated);
return response()->json([