Use formatted serving unit in other areas

This commit is contained in:
Christopher C. Wells 2021-02-06 13:53:56 -08:00 committed by Christopher Charbonneau Wells
parent afa4e5f93f
commit bf4cec4d27
4 changed files with 9 additions and 3 deletions

View File

@ -142,7 +142,9 @@ class JournalEntryController extends Controller
} }
// Update summary // 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) { foreach ($entries as $entry) {

View File

@ -69,6 +69,9 @@ use Spatie\Tags\HasTags;
* @property string|null $notes * @property string|null $notes
* @method static \Illuminate\Database\Eloquent\Builder|Food whereNotes($value) * @method static \Illuminate\Database\Eloquent\Builder|Food whereNotes($value)
* @method static \Illuminate\Database\Eloquent\Builder|Food whereSource($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 final class Food extends Model
{ {

View File

@ -41,6 +41,7 @@ use Illuminate\Support\Pluralizer;
* @method static \Illuminate\Database\Eloquent\Builder|IngredientAmount whereUpdatedAt($value) * @method static \Illuminate\Database\Eloquent\Builder|IngredientAmount whereUpdatedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder|IngredientAmount whereWeight($value) * @method static \Illuminate\Database\Eloquent\Builder|IngredientAmount whereWeight($value)
* @mixin \Eloquent * @mixin \Eloquent
* @property-read string|null $unit_formatted
*/ */
final class IngredientAmount extends Model final class IngredientAmount extends Model
{ {
@ -106,7 +107,7 @@ final class IngredientAmount extends Model
$unit = $this->ingredient->serving_unit_formatted; $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)); $unit = Pluralizer::plural($unit, ceil($this->amount));
} }

View File

@ -38,7 +38,7 @@
<div class="text-sm text-gray-600" x-text="result.brand" x-show="result.brand"></div> <div class="text-sm text-gray-600" x-text="result.brand" x-show="result.brand"></div>
<div class="text-sm"> <div class="text-sm">
Serving size <span x-text="result.serving_size_formatted"></span> Serving size <span x-text="result.serving_size_formatted"></span>
<span x-text="result.serving_unit"></span> <span x-text="result.serving_unit_formatted"></span>
(<span x-text="result.serving_weight"></span>g) (<span x-text="result.serving_weight"></span>g)
</div> </div>
</div> </div>