Laravel in many to many sync section has an example:
You may also pass additional intermediate table values with the IDs:
$user->roles()->sync([1 => ['expires' => true], 2, 3]);
lets say we have this array retrived from user selected roles:
[2,3,1 => ['expires' => true]]
but this array will not remain like this.in fact both 3
and 1=> ..
has the array key equivalent to 1
.so the 3
will be overridden .at the end this array will be turned to :
[2,1 => ['expires' => true]] //array value 3 is removed
how may i solve this issue as i have no control over roles ids order?