User model:
public function positions()
{
return $this->belongsToMany(\'App\\Position\')->withPivot(\'company_id\')->withTimestamps();
}
You are actually pretty close. The required format is:
[
98 => ['company_id' => 129],
99 => ['company_id' => 130],
100 => ['company_id' => 131]
]
This should generate the correct array:
$extra = array_map(function($companyId){
return ['company_id' => $companyId];
}, $allCompanyIds);
$data = array_combine($allPositionIds, $extra);
$user->positions()->sync($data);