From 4b31f87f98b73bf90c5fc67005f7a7a04ec33d8b Mon Sep 17 00:00:00 2001 From: "Christopher C. Wells" Date: Thu, 11 Mar 2021 19:28:38 -0800 Subject: [PATCH] Delete ingredient amounts on recipe delete --- app/Http/Controllers/RecipeController.php | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/app/Http/Controllers/RecipeController.php b/app/Http/Controllers/RecipeController.php index 2900882..fba8743 100644 --- a/app/Http/Controllers/RecipeController.php +++ b/app/Http/Controllers/RecipeController.php @@ -273,10 +273,17 @@ class RecipeController extends Controller */ public function destroy(Recipe $recipe): RedirectResponse { - // Remove the recipe from any recipes. - foreach ($recipe->ingredientAmountRelationships as $ia) { + // Remove recipe ingredients. + foreach ($recipe->ingredientAmounts as $ia) { $ia->delete(); } + + // Remove the recipe from any recipes. + foreach ($recipe->ingredientAmountRelationships as $iar) { + $iar->delete(); + } + + // Remove the recipe. $recipe->delete(); return redirect(route('recipes.index')) ->with('message', "Recipe {$recipe->name} deleted!");