コースモデルで:
public function sections()
{
return $this->hasMany('App\Section');
}
セクションモデル:
public function course()
{
return $this->belongsTo('App\Course');
}
public function lectures()
{
return $this->hasMany('App\Lecture');
}
講義モデル:
public function section()
{
return $this->belongsTo('App\Section');
}
public function lectures_comments()
{
return $this->hasMany('App\LecturesComment');
}
LecturesCommentモデル:
public function lecture()
{
return $this->belongsTo('App\Lecture');
}
、必要なデータを受信するには、あなたが歩く必要がありますth大まかな関係。
$comment = LecturesComment::find(1);
$courseName = $comment->lecture->section->course->title
はそれが役に立つことを願っています:)
:あなたは正しく外部キーを作成した場合
、このコードは、コースのタイトルを返します。