你如何处理这种情况? 在laravel这是直截了当的
$contracts = Contracts::with('bidinvitations')->with('bidinvitations.planentries)->where('created_at','2017-02-1')->get();
这样做的前提是,在 where子句旁边,列(例如 created_at )必须来自父表(合约)。
如何查询来自另一个表的where子句,例如
$contracts = Contracts::with('bidinvitations')->with('bidinvitations.planentries)->where('bidinvitations.planentries.created_at','2017-02-1')->get();
此查询:
where(**'bidinvitations.planentries.created_at'**,'2017-02-1')
只是没有工作
答案 0 :(得分:1)
你可以做这样的事情
$createdAt = '2017-02-1';
$contracts = Contracts::with(['bidinvitations' => function($bidinvitations_query) use($createdAt) {
$bidinvitations_query->with(['planentries' =>
function($planentries_query) use($createdAt) {
$planentries_query->where('created_at', $createdAt);
}
]);
}])->get();