public static function editIngredients($ingredients, $id, $ingredient_ids, $amounts, $units) { $i = 0; foreach ($ingredients as $ingredient) { $ingredient = strtolower($ingredient); if (Ingredient::alreadyInArchive($ingredient) > 0) { $ingredient_id = Ingredient::alreadyInArchive($ingredient); $old_ingredient_id = $ingredient_ids[$i]; $newDrinkIngredient = new DrinkIngredient(); $newDrinkIngredient->setIngredient_id($ingredient_id); $newDrinkIngredient->setDrink_id($id); $newDrinkIngredient->setAmount($amounts[$i]); $newDrinkIngredient->setUnit($units[$i]); $newDrinkIngredient->update($old_ingredient_id); } else { $newIngredient = new Ingredient(); $newIngredient->setIngredient_name($ingredient); $ingredient_id = $newIngredient->save(); $old_ingredient_id = $ingredient_ids[$i]; $newDrinkIngredient = new DrinkIngredient(); $newDrinkIngredient->setIngredient_id($ingredient_id); $newDrinkIngredient->setDrink_id($id); $newDrinkIngredient->setAmount($amounts[$i]); $newDrinkIngredient->setUnit($units[$i]); $newDrinkIngredient->update($old_ingredient_id); } $i++; } }