Laravel 5: synching an extra field via pivot
问题 User model: public function positions() { return $this->belongsToMany('App\Position')->withPivot('company_id')->withTimestamps(); } Positions model: public function users() { return $this->belongsToMany('App\User')->withPivot('company_id')->withTimestamps(); } On form submission I have two arrays: $allPositionIds array:3 [ 0 => 98 1 => 99 2 => 100 ] $allCompanyIds array:3 [ 0 => 129 1 => 130 2 => 131 ] Using $user->positions()->sync($allPositionIds); that syncs the position_user table as