Results(game_id, score)
Games(start, end, threshold)
给出时间戳: 我想找到所有属于游戏的结果,并带有一个开始和放大器。结束时间包含时间戳时间和结果分数高于游戏阈值的位置。
我已设法查询时间条件,但如何另外查询Results.score > games.threshold
?
Results::whereHas('game', function($q) use ($timestamp) {
$q->where('start', '<=', $timestamp)
->where('end', '>=', $timestamp)
})->with('game')->get()
答案 0 :(得分:3)
尝试在whereHas中使用whereRaw并检查它是否有效:
Results::whereHas('game', function($q) use ($timestamp) {
$q->where('start', '<=', $timestamp)
->where('end', '>=', $timestamp)
->whereRaw('results.score > games.threshold');
})->with('game')->get();