Laravel Eloquent 在数据特定字段上使用 where
Laravel Eloquent use where on with data specific field
这是我的代码:
$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
。
实际上我有这个错误“
Unknown column 'blocks.cards.id' in 'where clause'
".
有人知道如何正确执行此操作吗?谢谢!
试试这个,
$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);
因为你已经处于那种关系中所以回电
这是我的代码:
$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
。
实际上我有这个错误“
Unknown column 'blocks.cards.id' in 'where clause'
".
有人知道如何正确执行此操作吗?谢谢!
试试这个,
$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);
因为你已经处于那种关系中所以回电