我正在開發(fā)一個產品,我需要以某種形式獲取數(shù)據(jù)我的桌子是培訓班 :ID標題.... 其他領域course_termID教師編號course_id團體.... 其他領域老師IDname.... 其他領域這是多對多的關系!我需要我的老師模型在此表格上返回屬于它的課程[ { course_id: '', title: '', groups: ['A', 'B'] // the groups the teacher has }]我已經得到了課程,但它是這種格式[ { course_id: '', title: '', pivot: { group: 'A', } }, { course_id: '', title: '', pivot: { group: 'B', } }]代碼是return $this->belongsToMany(Course::class,CourseTerm::class) ->withPivot('group');有什么建議 ?
1 回答

慕斯王
TA貢獻1864條經驗 獲得超2個贊
嘗試刪除withPivot('group')
并附with('group')
加到控制器的代碼
return $this->belongsToMany(Course::class,CourseTerm::class);
在你的控制器中
Teacher::with('group');
- 1 回答
- 0 關注
- 171 瀏覽
添加回答
舉報
0/150
提交
取消