我有 2 个模型:Tours.php
public function includes()
{
return $this->belongsToMany('App\Included');
}
包含.php
public function tours()
{
return $this->belongsToMany('App\Tour');
}
以及我的TourController.php
store
方法中的以下代码:
if (isset($request->includeds) && isset($request->excludeds)) {
$tour->includes()->sync($request->includeds, false);
$tour->excludes()->sync($request->excludeds, false);
}
当我执行 dd($request->includeds);
时,我可以从表单中看到即将到来的值,但无法将其同步到我的数据透视表 included_tour
中代码同步excluded_tour
,没有任何错误。
最佳答案
一切似乎都是正确的。如果仍然无法正常工作,请尝试以下代码片段:
public function includes()
{
return $this->belongsToMany('App\Included','included_tour', 'tour_id', 'included_id');
}
关于php - 无法同步条件数据透视表多对多关系 Laravel,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42526001/