diff --git a/app/Http/Controllers/JournalEntryController.php b/app/Http/Controllers/JournalEntryController.php index a6ca7ce..4f14e6d 100644 --- a/app/Http/Controllers/JournalEntryController.php +++ b/app/Http/Controllers/JournalEntryController.php @@ -144,7 +144,15 @@ class JournalEntryController extends Controller } // Update summary - $unit = $item->serving_unit_formatted ?? $ingredient['unit']; + if (empty($item->serving_unit) && empty($item->serving_unit_name)) { + $unit = null; + } + elseif (!empty($item->serving_unit_name)) { + $unit = $item->serving_unit_formatted; + } + else { + $unit = $ingredient['unit']; + } $entries[$entry_key]->summary .= (!empty($entries[$entry_key]->summary) ? ', ' : null); $entries[$entry_key]->summary .= "{$ingredient['amount']} {$unit} {$item->name}"; } diff --git a/app/Models/Food.php b/app/Models/Food.php index 808b23d..1de55f3 100644 --- a/app/Models/Food.php +++ b/app/Models/Food.php @@ -136,9 +136,13 @@ final class Food extends Model * Get the "formatted" serving unit (for custom unit support). */ public function getServingUnitFormattedAttribute(): ?string { - $unit = $this->serving_unit; - if (empty($unit)) { - $unit = $this->serving_unit_name ?? null; + // No unit or unit name can be used for e.g. "bell pepper" or "onion" so + // the food name will be displayed directly. + if (empty($this->serving_unit) && empty($this->serving_unit_name)) { + $unit = null; + } + else { + $unit = $this->serving_unit_name ?? $this->serving_unit ?? 'serving'; } return $unit; }