我需要做一個查詢,我需要檢查是否最後兩行的列answered
等於字符串'不'。這是在我的控制器中,如果循環條件:Laravel - 查詢最後兩個等於
$inactive = Answer::orderBy('created_at', 'desc')
->where('answered', 'not')
->where('player_id', $player->id)
->where('quiz_id', $quiz->id)
->take(2);
if ($inactive) {
// The game was finished
$opponent = $quiz->getOpponent($player);
$quiz->status = 'finished';
$quiz->save();
Event::fire(new GameEvent(
'quizFinished',
[
$opponent->user,
$player->user,
],
[]
));
}
但它不工作,我期望的,因爲如果即使它不應該是循環被輸入。