Laravel多对多表

时间:2018-11-02 12:20:40

标签: laravel model

我有4张桌子:

members: id, lastname
license_member:id,license_id,member_id,valid_from
lesson_license_member: id,lesson_id,notes,license_member_id
lessons: id, number, date_time,instructor_id

在模型中:

Member.php

public function licenses(){
        return $this->belongsToMany(License::class)->withPivot('valid_from','id');
}

LicenseMember:

public function lessons(){
        return $this->belongsToMany(Lesson::class,'lesson_license_member','license_member_id','lesson_id')->withPivot('notes');
    }

课程:

 public function LicenseMember(){
        return $this->belongsToMany(LicenseMember::class,'lesson_license_member','license_member_id','lesson_id')->withPivot('notes');
    }

MemberController:

public function show($id)
    {
        $member = Member::find($id);
        return view('admin.members.members_detail',compact('member','id'));
    }

现在,在我看来,我想为所选成员显示他所拥有的每个许可证的课程(日期时间,编号和讲师ID)

我该怎么做?

0 个答案:

没有答案