我在这里有一个小但复杂的问题,我将尽我所能解释它。
First i有3个型号:Course
、Student
和Quiz
。
我有以下问题:
$course = Course::whereSlug($slug)->first(); // Some Course
$quizzes = $course->students()->with('quizzes'); // <-- Here lies the problem.
在最后一句话中,我想将此查询编辑为如下所示:
$quizzes = $course->students()->with('quizzes)->where('course_id', $course->id);
我之所以这样做,是因为我只想抓取与Student
Course
模型和模型相关的测验。
向您提供完整的,之后我循环遍历vue组件中的$students
变量,如下所示:
<div v-for="student in students"></div>
我使用Student
模型进行循环,因为我还检索了测验以外的不同属性。
但当然,当我像上面的查询一样执行时,我最终检索了所有course_id
= $course_id
的学生的所有测验。
所需的
我想要过滤结果,以获得学生的测验,只有当他们有一个course_id
,无论当前课程的id是什么。
https://stackoverflow.com/questions/50749738
复制相似问题