mirror of https://github.com/kcal-app/kcal.git
Ensure tags persist from old form data
This commit is contained in:
parent
fa3c1ee69e
commit
cfa9e2c1eb
|
|
@ -53,8 +53,15 @@ class FoodController extends Controller
|
|||
*/
|
||||
public function edit(Food $food): View
|
||||
{
|
||||
// Convert string tags (from old form data) to a Collection.
|
||||
$food_tags = old('tags', $food->tags->pluck('name'));
|
||||
if (is_string($food_tags)) {
|
||||
$food_tags = new Collection(explode(',', $food_tags));
|
||||
}
|
||||
|
||||
return view('foods.edit')
|
||||
->with('food', $food)
|
||||
->with('food_tags', $food_tags)
|
||||
->with('nutrients', Nutrients::$all)
|
||||
->with('serving_units', new Collection([
|
||||
['value' => 'tsp', 'label' => 'tsp.'],
|
||||
|
|
|
|||
|
|
@ -125,8 +125,15 @@ class RecipeController extends Controller
|
|||
}
|
||||
}
|
||||
|
||||
// Convert string tags (from old form data) to a Collection.
|
||||
$recipe_tags = old('tags', $recipe->tags->pluck('name'));
|
||||
if (is_string($recipe_tags)) {
|
||||
$recipe_tags = new Collection(explode(',', $recipe_tags));
|
||||
}
|
||||
|
||||
return view('recipes.edit')
|
||||
->with('recipe', $recipe)
|
||||
->with('recipe_tags', $recipe_tags)
|
||||
->with('ingredients', $ingredients)
|
||||
->with('steps', $steps)
|
||||
->with('ingredients_units', Nutrients::$units);
|
||||
|
|
|
|||
|
|
@ -66,7 +66,8 @@
|
|||
type="text"
|
||||
name="serving_size"
|
||||
size="10"
|
||||
:value="old('serving_size', $old_value)"/>
|
||||
:value="old('serving_size', $old_value)"
|
||||
required/>
|
||||
</div>
|
||||
|
||||
<!-- Serving unit -->
|
||||
|
|
@ -91,7 +92,8 @@
|
|||
step="any"
|
||||
name="serving_weight"
|
||||
size="10"
|
||||
:value="old('serving_weight', $food->serving_weight)"/>
|
||||
:value="old('serving_weight', $food->serving_weight)"
|
||||
required/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
|
@ -113,7 +115,7 @@
|
|||
</div>
|
||||
|
||||
<!-- Tags -->
|
||||
<x-tagger :defaultTags="$food->tags->pluck('name')"/>
|
||||
<x-tagger :defaultTags="$food_tags"/>
|
||||
|
||||
<!-- Source -->
|
||||
<div class="flex-auto">
|
||||
|
|
|
|||
|
|
@ -60,7 +60,7 @@
|
|||
</div>
|
||||
|
||||
<!-- Tags -->
|
||||
<x-tagger :defaultTags="$recipe->tags->pluck('name')"/>
|
||||
<x-tagger :defaultTags="$recipe_tags"/>
|
||||
</div>
|
||||
|
||||
<!-- Ingredients -->
|
||||
|
|
|
|||
Loading…
Reference in New Issue