diff --git a/app/Http/Controllers/RecipeController.php b/app/Http/Controllers/RecipeController.php index 7572e77..295aa38 100644 --- a/app/Http/Controllers/RecipeController.php +++ b/app/Http/Controllers/RecipeController.php @@ -88,6 +88,7 @@ class RecipeController extends Controller continue; } $ingredients[] = [ + 'type' => 'ingredient', 'key' => $old['key'][$key], 'weight' => $old['weight'][$key], 'amount' => $old['amount'][$key], @@ -102,6 +103,7 @@ class RecipeController extends Controller else { foreach ($recipe->ingredientAmounts as $key => $ingredientAmount) { $ingredients[] = [ + 'type' => 'ingredient', 'key' => $key, 'weight' => $ingredientAmount->weight, 'amount' => $ingredientAmount->amount_formatted, @@ -114,6 +116,31 @@ class RecipeController extends Controller } } + $separators = []; + if ($old = old('separators')) { + foreach ($old['key'] as $index => $key) { + if (empty($key)) { + continue; + } + $separators[] = [ + 'type' => 'separator', + 'key' => $old['key'][$index], + 'weight' => $old['weight'][$index], + 'text' => $old['text'][$index], + ]; + } + } + else { + foreach ($recipe->ingredientSeparators as $key => $ingredientSeparator) { + $ingredients[] = [ + 'type' => 'separator', + 'key' => $key, + 'weight' => $ingredientSeparator->weight, + 'text' => $ingredientSeparator->text, + ]; + } + } + $steps = []; if ($old = old('steps')) { foreach ($old['step'] as $key => $step) { @@ -144,7 +171,7 @@ class RecipeController extends Controller return view('recipes.edit') ->with('recipe', $recipe) ->with('recipe_tags', $recipe_tags) - ->with('ingredients', $ingredients) + ->with('ingredients_list', new Collection([...$ingredients, ...$separators])) ->with('steps', $steps) ->with('ingredients_units', Nutrients::$units); } diff --git a/resources/views/recipes/edit.blade.php b/resources/views/recipes/edit.blade.php index 6e04894..6caa372 100644 --- a/resources/views/recipes/edit.blade.php +++ b/resources/views/recipes/edit.blade.php @@ -126,8 +126,12 @@