Refactor Brand, Category, and Product controllers to use createWithProps and updateWithProps methods for improved property synchronization

This commit is contained in:
2026-06-24 10:28:46 -03:00
parent 6a0080b475
commit 8e5814e333
4 changed files with 40 additions and 12 deletions

View File

@@ -23,8 +23,7 @@ class BrandController extends Controller
$props = $validated['props'] ?? [];
unset($validated['props']);
$brand = Brand::create($validated);
$brand->syncPropValues($props);
$brand = Brand::createWithProps($validated, $props);
return BrandResource::make($brand)->response()->setStatusCode(201);
}
@@ -40,8 +39,7 @@ class BrandController extends Controller
$props = $validated['props'] ?? [];
unset($validated['props']);
$marca->update($validated);
$marca->syncPropValues($props);
$marca = $marca->updateWithProps($validated, $props);
return BrandResource::make($marca);
}

View File

@@ -25,8 +25,7 @@ class CategoryController extends Controller
$props = $validated['props'] ?? [];
unset($validated['props']);
$category = Category::create($validated);
$category->syncPropValues($props);
$category = Category::createWithProps($validated, $props);
return CategoryResource::make($category->load(['parent', 'subCategories', 'tenant']))
->response()
@@ -44,8 +43,7 @@ class CategoryController extends Controller
$props = $validated['props'] ?? [];
unset($validated['props']);
$categoria->update($validated);
$categoria->syncPropValues($props);
$categoria = $categoria->updateWithProps($validated, $props);
return CategoryResource::make($categoria->load(['parent', 'subCategories', 'tenant']));
}

View File

@@ -23,8 +23,7 @@ class ProductController extends Controller
$props = $validated['props'] ?? [];
unset($validated['props']);
$product = Product::create($validated);
$product->syncPropValues($props);
$product = Product::createWithProps($validated, $props);
return ProductResource::make($product)->response()->setStatusCode(201);
}
@@ -40,8 +39,7 @@ class ProductController extends Controller
$props = $validated['props'] ?? [];
unset($validated['props']);
$producto->update($validated);
$producto->syncPropValues($props);
$producto = $producto->updateWithProps($validated, $props);
return ProductResource::make($producto);
}