我正在尝试在急切加载的查询中按其他关系的列( results.draw_date )过滤 tickets.tips.drawDates 关系的数据。有人对如何做到这一点有什么建议吗?
$products = Product::with([
'results' => function ($query) use ($drawDates) {
return $query->whereBetween('draw_date', $drawDates);
},
'tickets' => function ($query) use ($drawDateFrom) {
return $query->whereDate('valid_until', '>=', $drawDateFrom)->where('status', 'pending');
},
'tickets.tips',
'tickets.tips.drawDates' => function($query) {
return $query->whereNull('status')->whereDate('draw_date', 'HERE SHOULD BE draw_date COLUMN FROM results RELATION');
},
'prizes'
])->get();
答案 0 :(得分:0)
您可以尝试使用whereColumn()
函数,该函数用于验证两列是否相等,如下所示:
return $query->whereNull('status')->whereColumn('draw_date', 'results.draw_date');