我從以下代碼中得到了意想不到的結果:$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 關注
- 219 瀏覽
添加回答
舉報
0/150
提交
取消