我从以下代码中得到了意想不到的结果:
$minutes = 0;
if($timeSpan === "game") {
//stuff
} elseif($timeSpan === "season") {
$games = Game::where('season_id', $timeSpanId)->where('team_id', $whoId)->where('stats_done', 'yes');
foreach($games as $game) {
$minutes += $game->periods * $game->period_length * 5;
}
}
return $minutes;
这将返回 0,但我知道这不是我想要得到的,而且数据库在那里有数据,所以不应该是这种情况。
快速上下文:
$timeSpan 确实等于“季节”,经过测试,我知道这不是问题
此处的游戏查询确实返回结果。我知道是因为我取出 foreach 并用 $minutes = $games->count() 替换它并得到 5
有人知道这可能是什么吗?我觉得我以前在 foreach 循环中遇到过这个问题,所以我期待了解我对它们的了解在哪里。
谢谢!
一只名叫tom的猫