From ce4827a8ec52b02535f6cc0c7348c8d48356e96a Mon Sep 17 00:00:00 2001 From: "Christopher C. Wells" Date: Sat, 12 Feb 2022 06:27:12 -0800 Subject: [PATCH] Account for serving sizes > 1 in recipe display Closes #19 --- resources/views/recipes/show.blade.php | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/resources/views/recipes/show.blade.php b/resources/views/recipes/show.blade.php index 1fdd731..6642ca7 100644 --- a/resources/views/recipes/show.blade.php +++ b/resources/views/recipes/show.blade.php @@ -43,8 +43,18 @@ @if($item::class === \App\Models\IngredientAmount::class)
  • - {{ \App\Support\Number::rationalStringFromFloat($item->amount) }} - @if($item->unitFormatted){{ $item->unitFormatted }}@endif + {{-- Prevent food with serving size > 1 from incorrectly using formatted + serving unit with number of servings. E.g., for a recipe calling for 1 + serving of a food with 4 tbsp. to a serving size show "1 serving" instead + of "1 tbsp." (incorrect). --}} + @if($item->unit === 'serving' && $item->ingredient->serving_size > 1 && ($item->ingredient->serving_unit || $item->ingredient->serving_unit_name)) + {{ \App\Support\Number::rationalStringFromFloat($item->amount * $item->ingredient->serving_size) }} {{ $item->unitFormatted }} + ({{ \App\Support\Number::rationalStringFromFloat($item->amount) }} {{ \Illuminate\Support\Str::plural('serving', $item->amount ) }}) + @else + {{ \App\Support\Number::rationalStringFromFloat($item->amount) }} + @if($item->unitFormatted){{ $item->unitFormatted }}@endif + @endif + @if($item->ingredient->type === \App\Models\Recipe::class)