私は Laravel 5.2 で ManyToMany 関係を持っています:
ユーザーモデル:
public function Lessons(){
return $this->belongsToMany('App\Lesson')->withPivot('created_by', 'number_of_lessons','id');
}
ただし、次のようにピボットテーブルに複数のレッスンを保存したい:
$output = [];
$output[] = $this->RidingCourses()->wherePivot('created_by',1)->first()->pivot->number_of_lessons = 200;
$output[] = $this->RidingCourses()->wherePivot('created_by',2)->first()->pivot->number_of_lessons = 200;
$this->RidingCourses()->saveMany([$output]);
ピボット レコードは更新されていますが、ピボット テーブルには 2 つの空白のレコードも作成されています。私の質問は、複数の ManyToMany 関連モデルを正しく保存するにはどうすればよいですか?