Laravel雄辩地使用where on和数据特定字段
这是我的代码:Laravel雄辩地使用where on和数据特定字段,laravel,eloquent,query-builder,relation,Laravel,Eloquent,Query Builder,Relation,这是我的代码: $course = Course::where('id', $activeCourseId) ->with(["blocks.cards" => function($q) use($cardsDueIds) { $q->whereNotIn('blocks.cards.id', $cardsDueIds); $q->take(50); },
$course = Course::where('id', $activeCourseId)
->with(["blocks.cards" => function($q) use($cardsDueIds) {
$q->whereNotIn('blocks.cards.id', $cardsDueIds);
$q->take(50);
},
"cards",
"blocks.cards.contexts",
"blocks.cards.user_contexts",
"blocks.cards.block.course",
"blocks.cards.thisUser"])
->first();
我尝试只获取block.cards
,其中每个block.cards['id']
不在$cardsDueIds
中
实际上我有这个错误“
“where子句”中的未知列“blocks.cards.id”
“
有人知道如何正确地做到这一点吗?谢谢 试试这个
$course = Course::where('id', $activeCourseId)
->with(["blocks.cards" => function($q) use($cardsDueIds) {
$q->whereNotIn('id', $cardsDueIds);
}])
->first();
试试这个
$course = Course::where('id', $activeCourseId)
->with(["blocks.cards" => function($q) use($cardsDueIds) {
$q->whereNotIn('id', $cardsDueIds);
}])
->first();
$q->whereNotIn('blocks.cards.id',$cardsDueIds);
到
$q->whereNotIn('id',$cardsDueIds);
由于您已经处于该关系中,请回调$q->whereNotIn('blocks.cards.id',$cardsDueIds);
到
$q->whereNotIn('id',$cardsDueIds);
由于您已经处于该关系中,请回调
$q->whereNotIn('blocks.cards.id',$cardsDueIds)代码>到$q->whereNotIn('id',$cardsDueIds)代码>既然你已经处于这种关系中,请回电,它会工作的,谢谢<代码>$q->whereNotIn('blocks.cards.id',$cardsDueIds)代码>到$q->whereNotIn('id',$cardsDueIds)代码>既然你已经处于这种关系中,请回电,它会工作的,谢谢!谢谢你的回答,我有一个“未定义上下文”错误。上下文字段在cards表中吗?不,它是一个关系。你已经在该关系中,所以你可以直接访问cards表字段。我已经更新了代码,您可以检查。很抱歉whereNotIn不起作用,只有当我删除“->take(50)”时它才起作用。谢谢您的回答,我有一个“未定义上下文”错误。上下文字段在cards表中吗?不,它是一个关系您已经处于该关系中,因此您可以直接访问cards表字段。我已经更新了代码,您可以查看。很抱歉,whereNotIn不起作用,只有在我删除“->take(50)”时它才起作用