From 713da8f72854cc2b1c2987e78a748dd6a356326c Mon Sep 17 00:00:00 2001 From: "Christopher C. Wells" Date: Wed, 10 Feb 2021 06:02:15 -0800 Subject: [PATCH] Default food nutrients to zero --- app/Http/Controllers/FoodController.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/app/Http/Controllers/FoodController.php b/app/Http/Controllers/FoodController.php index eea1a2f..a92e2ec 100644 --- a/app/Http/Controllers/FoodController.php +++ b/app/Http/Controllers/FoodController.php @@ -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.