Prevent potential division by zero error

This commit is contained in:
Christopher C. Wells 2021-05-15 21:40:12 -07:00 committed by Christopher Charbonneau Wells
parent 86b61dba30
commit ce9bf83221
1 changed files with 4 additions and 2 deletions

View File

@ -46,8 +46,10 @@ class JournalEntryController extends Controller
$goalProgress = [];
if ($goal) {
foreach (Nutrients::all()->pluck('value') as $nutrient) {
$goalProgress[$nutrient] = round($sums[$nutrient] / $goal->{$nutrient} * 100);
$goalProgress[$nutrient] .= '%';
if ($goal->{$nutrient} > 0) {
$goalProgress[$nutrient] = round($sums[$nutrient] / $goal->{$nutrient} * 100);
$goalProgress[$nutrient] .= '%';
}
}
}