1 回答

TA貢獻1875條經驗 獲得超3個贊
您在關系中傳遞了錯誤的參數。
如果你在User.php模型參數應該是。
return $this->belongsToMany(CustomLanguage::class,'custom_language_user','user_id','lang_id')->withPivot('lang_id','user_id');
如果你在CustomLanguages.php模型參數應該是。
return $this->belongsToMany(User::class,'custom_language_user','lang_id','user_id')->withPivot('lang_id','user_id');
所以現在你的模型看起來像。
//App\User.php
public function languages() {
return $this->belongsToMany(CustomLanguage::class,'custom_language_user','user_id','lang_id')->withPivot('lang_id','user_id');
}
//App\CustomLanguages.php
public function users() {
return $this->belongsToMany(User::class,'custom_language_user','lang_id','user_id')->withPivot('user_id','lang_id');
}
- 1 回答
- 0 關注
- 159 瀏覽
添加回答
舉報