gpt4 book ai didi

php - Laravel,在 Eloquent 语法中应用 where after with

转载 作者:太空宇宙 更新时间:2023-11-03 12:15:52 25 4
gpt4 key购买 nike

我正在尝试按类别获取所有问题,其中问题的作者是 Y

这就是我尝试这样做的方式:

QuestionCategory::with('questions')->where('questions.source', '=', $userId)->get();

问题是,它没有将 where 应用到 questions 表,而是应用到 question_categories 表。

Column not found: 1054 Unknown column 'questions.source' in 'where clause' (SQL: select * from question_categories where questions.source = 2)

知道我错过了什么吗?

最佳答案

问题表在单独的查询中预先加载,因此您的 where 语句无权访问问题表。

您必须加入它才能查询它。

QuestionCategory::with('questions')
->join('questions', 'question_id', '=', 'questions.id')
->where('questions.source', '=', $userId)
->get();

关于php - Laravel,在 Eloquent 语法中应用 where after with,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22250839/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com