diff --git a/app/Http/Controllers/SubCategoryController.php b/app/Http/Controllers/SubCategoryController.php index 95b2f02..ff96eee 100644 --- a/app/Http/Controllers/SubCategoryController.php +++ b/app/Http/Controllers/SubCategoryController.php @@ -5,6 +5,7 @@ use App\Models\SubCategory; use App\Http\Requests\StoreSubCategoryRequest; use App\Http\Requests\UpdateSubCategoryRequest; +use Illuminate\Http\Client\Request; use Illuminate\Http\JsonResponse; class SubCategoryController extends Controller @@ -58,18 +59,17 @@ public function show($id): JsonResponse /** * Update the specified resource in storage. */ - public function update(UpdateSubCategoryRequest $request, SubCategory $subCategory): JsonResponse + public function update(Request $request, SubCategory $subCategory) { - $subCategory->update($request->all()); - - return response()->json([ - 'status' => 'success', - 'message' => 'SubCategory updated successfully', - 'data' => $subCategory, + $validated = $request->validate([ + 'name' => 'required|max:255', + 'category_id' => 'required', ]); + return $subCategory->update($request->all()); } + public function destroy(SubCategory $subcategory) { $subcategory->delete(); diff --git a/app/Models/subCategory.php b/app/Models/subCategory.php index 490e9d7..049bc0a 100644 --- a/app/Models/subCategory.php +++ b/app/Models/subCategory.php @@ -1,5 +1,7 @@