Default food nutrients to zero

This commit is contained in:
Christopher C. Wells 2021-02-10 06:02:15 -08:00
parent 3c5d1c1f00
commit 713da8f728
1 changed files with 8 additions and 0 deletions

View File

@ -93,6 +93,14 @@ class FoodController extends Controller
]);
$attributes['serving_size'] = Number::floatFromString($attributes['serving_size']);
$attributes['name'] = Str::lower($attributes['name']);
// Default nutrients to zero.
foreach (Nutrients::$all as $nutrient) {
if (is_null($attributes[$nutrient['value']])) {
$attributes[$nutrient['value']] = 0;
}
}
$food->fill($attributes)->save();
// Sync tags.