【发布时间】:2017-07-20 12:38:57
【问题描述】:
我正在安装 Laravel(除其他外)
- 教师(table:users (cols: id, name, type), model:User, users.type = 2)
- 学生(表:用户(id、姓名、类型)、模型:用户、users.type = 1)
- 学校(表:学校(id,名称),型号:学校)
- 学生集合(表:student_collection (id, name),模型:StudentCollection)
- & 表 student_collections_users 用于将学生用户链接到集合(模型:StudentCollections、列 id、user_id、collection_id)
我已经设法建立了一些关系,但我无法理解
- 哪些老师教学生
- 学生属于哪些收藏
目前我正在尝试使用
//User.php
public function collections() {
$collection = $this->hasManyThrough('\App\StudentsCollections', '\App\User', 'id', 'user_id');
return $collection;
}
//Controller
$user = \App\User::find($id);
$user->collections = $user->collections();
但它只返回集合的 id。如何获取每个集合的完整数据对象?
我正在使用 Laravel 5.3。
【问题讨论】: