2017-03-01 126 views
0

我有2種型號:Tours.php無法同步條件的數據透視表多對多的關係laravel

public function includes() 
{ 
    return $this->belongsToMany('App\Included'); 
} 

Included.php

public function tours() 
{ 
    return $this->belongsToMany('App\Tour'); 
} 

和下面的代碼在我TourController.phpstore方法:

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沒有任何錯誤。

回答

2

一切似乎都是正確的。如果它仍然無法正常工作,請嘗試以下代碼片段:

public function includes() 
{ 
    return $this->belongsToMany('App\Included','included_tour', 'tour_id', 'included_id'); 
}