我想在同一个类上实现多到多的关系。课程有必修课。附加工作从修补,但不是从控制器。
$course->pre_reqs()->attach(int); // works from tinker
//does not work from controller (I checked that $course is the right object)
$course = DB::table('courses')->where('id', $id1)->first();
$course->pre_reqs()->attach(10);
//from model
public function pre_reqs()
{
return $this->belongsToMany('App\Course', 'pre_req', 'course_id', 'pre_req_course_id' );
}枢轴表适用于修补器。
错误是
调用未定义方法pre_reqs
发布于 2016-10-23 04:37:59
试着用模型类
$course = Course::where('id', $id1)->first();
$course->pre_reqs()->attach(10);https://stackoverflow.com/questions/40197353
复制相似问题