public static function createRecipe($yeild, $yeildUnit, $method, $recipeName, $recipeCost, $ingredients = array()) { $user = new User(); $userId = $user->data()->id; $db = self::getInstance(); //first create the recipe $sql = "INSERT INTO `Recipes` (`user`, `yeild`, `yeildUnit`, `method`, `recipeName`, `recipeCost`) VALUES ( ?, ?, ?, ?, ?, ?);"; if ($db->query($sql, [$userId, $yeild, $yeildUnit, $method, $recipeName, $recipeCost])) { //then add ingredients $recipeId = $db->getLastInsertId(); foreach ($ingredients as $ingredient) { Ingredient::addIngredient($recipeId, $ingredient['productId'], $ingredient['quantity'], $ingredient['unit']); } return true; } else { return false; } }