From bf4cec4d2731ba1d3a9fce047f05630a125a241e Mon Sep 17 00:00:00 2001 From: "Christopher C. Wells" Date: Sat, 6 Feb 2021 13:53:56 -0800 Subject: [PATCH] Use formatted serving unit in other areas --- app/Http/Controllers/JournalEntryController.php | 4 +++- app/Models/Food.php | 3 +++ app/Models/IngredientAmount.php | 3 ++- resources/views/components/ingredient-picker.blade.php | 2 +- 4 files changed, 9 insertions(+), 3 deletions(-) diff --git a/app/Http/Controllers/JournalEntryController.php b/app/Http/Controllers/JournalEntryController.php index f71a185..d238f96 100644 --- a/app/Http/Controllers/JournalEntryController.php +++ b/app/Http/Controllers/JournalEntryController.php @@ -142,7 +142,9 @@ class JournalEntryController extends Controller } // Update summary - $entries[$entry_key]->summary .= (!empty($entries[$entry_key]->summary) ? ', ' : null) . "{$ingredient['amount']} {$ingredient['unit']} {$item->name}"; + $unit = $item->serving_unit_formatted ?? $ingredient['unit']; + $entries[$entry_key]->summary .= (!empty($entries[$entry_key]->summary) ? ', ' : null); + $entries[$entry_key]->summary .= "{$ingredient['amount']} {$unit} {$item->name}"; } foreach ($entries as $entry) { diff --git a/app/Models/Food.php b/app/Models/Food.php index 463b120..808b23d 100644 --- a/app/Models/Food.php +++ b/app/Models/Food.php @@ -69,6 +69,9 @@ use Spatie\Tags\HasTags; * @property string|null $notes * @method static \Illuminate\Database\Eloquent\Builder|Food whereNotes($value) * @method static \Illuminate\Database\Eloquent\Builder|Food whereSource($value) + * @property string|null $serving_unit_name + * @property-read string|null $serving_unit_formatted + * @method static \Illuminate\Database\Eloquent\Builder|Food whereServingUnitName($value) */ final class Food extends Model { diff --git a/app/Models/IngredientAmount.php b/app/Models/IngredientAmount.php index 5f1c493..f132abc 100644 --- a/app/Models/IngredientAmount.php +++ b/app/Models/IngredientAmount.php @@ -41,6 +41,7 @@ use Illuminate\Support\Pluralizer; * @method static \Illuminate\Database\Eloquent\Builder|IngredientAmount whereUpdatedAt($value) * @method static \Illuminate\Database\Eloquent\Builder|IngredientAmount whereWeight($value) * @mixin \Eloquent + * @property-read string|null $unit_formatted */ final class IngredientAmount extends Model { @@ -106,7 +107,7 @@ final class IngredientAmount extends Model $unit = $this->ingredient->serving_unit_formatted; } - if ($unit && $unit != 'tsp' && $unit != 'tbsp') { + if ($unit && $unit != 'tsp' && $unit != 'tbsp'&& $unit != 'oz') { $unit = Pluralizer::plural($unit, ceil($this->amount)); } diff --git a/resources/views/components/ingredient-picker.blade.php b/resources/views/components/ingredient-picker.blade.php index 89ab1a2..db42ab8 100644 --- a/resources/views/components/ingredient-picker.blade.php +++ b/resources/views/components/ingredient-picker.blade.php @@ -38,7 +38,7 @@
Serving size - + (g)