mirror of https://github.com/kcal-app/kcal.git
Set formatted serving size to null when empty
This commit is contained in:
parent
fafc4c9e33
commit
65e3e9c776
|
@ -156,8 +156,12 @@ final class Food extends Model
|
||||||
/**
|
/**
|
||||||
* Get the serving size as a formatted string (e.g. 0.5 = 1/2).
|
* Get the serving size as a formatted string (e.g. 0.5 = 1/2).
|
||||||
*/
|
*/
|
||||||
public function getServingSizeFormattedAttribute(): string {
|
public function getServingSizeFormattedAttribute(): ?string {
|
||||||
return Number::fractionStringFromFloat($this->serving_size);
|
$result = null;
|
||||||
|
if (!empty($this->serving_size)) {
|
||||||
|
$result = Number::fractionStringFromFloat($this->serving_size);
|
||||||
|
}
|
||||||
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -46,13 +46,6 @@
|
||||||
|
|
||||||
<div class="flex flex-col space-y-4 sm:flex-row sm:space-x-4 sm:space-y-0">
|
<div class="flex flex-col space-y-4 sm:flex-row sm:space-x-4 sm:space-y-0">
|
||||||
<!-- Serving size -->
|
<!-- Serving size -->
|
||||||
@php
|
|
||||||
if (!empty($food->serving_size)) {
|
|
||||||
$old_value = \App\Support\Number::fractionStringFromFloat($food->serving_size);
|
|
||||||
} else {
|
|
||||||
$old_value = null;
|
|
||||||
}
|
|
||||||
@endphp
|
|
||||||
<div>
|
<div>
|
||||||
<x-inputs.label for="serving_size" value="Serving size"/>
|
<x-inputs.label for="serving_size" value="Serving size"/>
|
||||||
|
|
||||||
|
@ -61,7 +54,7 @@
|
||||||
type="text"
|
type="text"
|
||||||
name="serving_size"
|
name="serving_size"
|
||||||
size="10"
|
size="10"
|
||||||
:value="old('serving_size', $old_value)"
|
:value="old('serving_size', $food->serving_size_formatted)"
|
||||||
required/>
|
required/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue