Delete ingredient amounts on recipe delete

This commit is contained in:
Christopher C. Wells 2021-03-11 19:28:38 -08:00
parent af65c5c7bb
commit 4b31f87f98
1 changed files with 9 additions and 2 deletions

View File

@ -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!");