多对多关联更为复杂。
中间表:php artisan make:model Models/GradeStudent -m

课程表:php artisan make:migration create_grade
php artisan make:model Models/Grade -m

学生表:php artisan make:migration create_student
php artisan make:model Models/Student -m

belongsToMany('关联模型','中间表','外键','关联键');
关联模型(必须):模型名或者模型类名
中间表:默认规则是当前模型名+_+关联模型名 (可以指定模型名)
外键 :中间表的当前模型外键,默认的外键名规则是关联模型名+_id
关联键:中间表的关联模型关联键名,默认规则是关联模型名+_id
在student模型中:
通过中间表 gradestatus找到关联表grade
Public function grade(){
1.要关联的表 2,中间表3 当前模型在中间表外键 4,要关联的模型在中间表的外键
Return$this->belongstomany(‘grade::class’,’grade_students’,’student_id’ ,’grade_id’);
}
定义关联关系:注意这里我们直接使用了中间表的方式

