diff --git a/app/Models/Food.php b/app/Models/Food.php
index 9d89006..ed533d0 100644
--- a/app/Models/Food.php
+++ b/app/Models/Food.php
@@ -105,7 +105,7 @@ class Food extends Model
protected $appends = ['serving_size_formatted'];
/**
- * Get the serving size as a fractional.
+ * Get the serving size as a formatted string (e.g. 0.5 = 1/2).
*/
public function getServingSizeFormattedAttribute(): string {
return Number::fractionStringFromFloat($this->serving_size);
diff --git a/app/Models/FoodAmount.php b/app/Models/FoodAmount.php
index aba62ba..232a568 100644
--- a/app/Models/FoodAmount.php
+++ b/app/Models/FoodAmount.php
@@ -2,6 +2,7 @@
namespace App\Models;
+use App\Support\Number;
use App\Support\Nutrients;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
@@ -74,6 +75,18 @@ class FoodAmount extends Model
'sodium',
];
+ /**
+ * @inheritdoc
+ */
+ protected $appends = ['amount_formatted'];
+
+ /**
+ * Get the amount as a formatted string (e.g. 0.5 = 1/2).
+ */
+ public function getAmountFormattedAttribute(): string {
+ return Number::fractionStringFromFloat($this->amount);
+ }
+
/**
* Get the Food this amount belongs to.
*/
diff --git a/resources/views/recipes/edit.blade.php b/resources/views/recipes/edit.blade.php
index 1182ff4..552eead 100644
--- a/resources/views/recipes/edit.blade.php
+++ b/resources/views/recipes/edit.blade.php
@@ -64,50 +64,32 @@
- @foreach($recipe->foodAmounts as $foodAmount)
-
- @endforeach
-
+ @if(old('ingredients'))
+ @foreach(old('ingredients') as $i => $ingredient)
+ @if (empty($ingredient) && empty(old('ingredients_amount')[$i]) && empty(old('ingredients_unit')[$i]))
+ @continue
+ @endif
+ @include('recipes.partials.ingredient-input', [
+ 'amount' => old('ingredients_amount')[$i],
+ 'unit' => old('ingredients_unit')[$i],
+ 'food_id' => old('ingredients')[$i],
+ 'food_name' => old('ingredients_name')[$i],
+ 'detail' => old('ingredients_detail')[$i],
+ ])
+ @endforeach
+ @else
+ @foreach($recipe->foodAmounts as $foodAmount)
+ @include('recipes.partials.ingredient-input', [
+ 'amount' => $foodAmount->amount_formatted,
+ 'unit' => $foodAmount->unit,
+ 'food_id' => $foodAmount->food->id,
+ 'food_name' => $foodAmount->food->name,
+ 'detail' => $foodAmount->detail,
+ ])
+ @endforeach
+ @endif
-
+ @include('recipes.partials.ingredient-input')