【发布时间】:2018-08-01 00:26:33
【问题描述】:
请给我三个模型:讲师、级别、课程。
讲师表
| ID | Name_of_lecturer
+----+----------------
| 1 .| Prof John Doe
+----+----------------
| 2 .| Prof Jane Doe
等级表
| ID | Name
+----+----------------
| 1 .| Level 1
+----+----------------
| 2 .| Level 2
课程表
| ID | level_id | lecturer_id | course_info
+----+----------+-------------+----------------------------------
| 1 | 2 | 3 a topic in level 2 by lecturer 3
+----+----------+-------------+----------------------------------
| 2 | 5 | 6 | a topic in level 5 by lecturer 6
我真的很困惑如何使用 Eloquent 从 Levels 模型中获取每门课程的讲师详细信息。任何帮助将不胜感激。提前致谢。
【问题讨论】:
-
你能在问题的最后加上你的预期结果吗?
-
我阅读了文档并遇到了各种错误。我希望能够从级别模型中访问它,在那里我可以获得所有课程及其各自的讲师。谢谢。
-
Lecturer和Level之间存在BelongsToMany关系。看看documentation。
标签: php mysql laravel eloquent