我从以下代码中得到了意想不到的结果:$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 循环中遇到过这个问题,所以我期待了解我对它们的了解在哪里。谢谢!
1 回答
一只名叫tom的猫
TA贡献1906条经验 获得超3个赞
正如我所评论的,实际上您只是缺少get()
将检索执行查询的结果。所以请执行如下
$games = Game::where('season_id', $timeSpanId)->where('team_id', $whoId)->where('stats_done', 'yes')->get();
- 1 回答
- 0 关注
- 189 浏览
添加回答
举报
0/150
提交
取消