【发布时间】:2015-06-04 04:07:20
【问题描述】:
我有以下雄辩的模型:
[用户]
public function studentProfile()
{
return $this->hasOne('App\StudentProfile');
}
public function tutorProfile()
{
return $this->hasOne('App\TutorProfile');
}
[学生档案]
public function user()
{
return $this->belongsTo('App\User');
}
public function tutorialLogs()
{
return $this->hasMany('App\TutorialLog', 'student_profile_id');
}
[导师简介]
public function user()
{
return $this->belongsTo('App\User');
}
public function tutorialLogs()
{
return $this->hasMany('App\TutorialLog', 'tutor_profile_id');
}
[教程日志]
public function tutorProfile()
{
return $this->belongsTo('App\TutorProfile');
}
public function studentProfile()
{
return $this->belongsTo('App\StudentProfile');
}
我的数据库结构也是这样的:
[用户]
id
fname
[学生档案]
id
notes
user_id
[tutor_profiles]
id
speciality
user_id
[教程日志]
id
notes
student_profile_id
tutor_profile_id
我正在尝试根据tutor_profile_id 获取导师的教程日志。我已经这样做了,但是当我要获得导师姓名或学生姓名时,我无法获得。
这是我的代码:
$tutor = User::whereId(Auth::user()->id)->first();
// get the tutorial logs
$tutorial_logs = $tutor->tutorProfile->tutorialLogs()->orderBy('date')->get();
我不知道如何访问视图中的学生 fname 或导师 fname。
有什么帮助吗?谢谢
【问题讨论】:
标签: php laravel orm eloquent blade