Laravel eloquent 使用 whereNotIn 和 Take 关系数据

Laravel eloquent use whereNotIn and Take in relationship data

这是我的代码:

$course = Course::where('id', $activeCourseId)
        ->with(["blocks.cards" => function($q) use($cardsDueIds) {
            $q->whereNotIn('id', $cardsDueIds);
            $q->take(50);
        },
        "blocks.cards.contexts",
        "blocks.cards.user_contexts",
        "blocks.cards.block.course",
        "blocks.cards.thisUser"])
        ->first();

课程数据是这样的:

{
  blocks: [
    0: {
      cards: [
       0: {id: 298736},
       1: {id: 293747}
      ]
    }
    1: {
      cards: [
       0: {id: 1234445}
      ]
    }
  ]
}

我尝试只用 50 blocks.cards 获得课程,其中 blocks.cards.id 不在 $cardsDueIds

实际上它不起作用,使用 take(50) 我得到 0 张卡片,没有 take(50) 我得到所有卡片(但 whereNotIn 不起作用)...

有人知道怎么做吗?谢谢!

$q->whereNotIn('id', $cardsDueIds)->take(50);

如果不行,参考这个

请重新回答你的问题(你说了两次一样):

Actually it does not work, with take(50) i get 0 cards and with take(50) i get all cards...