Tuesday, February 28, 2017

Unable to sync conditional pivot table many to many relationship laravel

I have 2 models : Tours.php

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

Included.php

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

and below code in my TourController.php store method:

if (isset($request->includeds) && isset($request->excludeds)) {
      $tour->includes()->sync($request->includeds, false);
      $tour->excludes()->sync($request->excludeds, false);
}

when i do dd($request->includeds); I can see the coming values from the form but unable to sync it in my pivot table included_tour while the code syncs excluded_tour without any error.




via Zachary Dale

Advertisement