I'm wondering if there is a difference between the two following Eloquent instructions that update the data on the role_user pivot table of a many-to-many relationship between User and Role models.
// Attach the specified roles to the user
$user–>roles()–>attach([1, 2, 3]);
// Sync the specified roles without detaching the one previously assigned to the user
$user–>roles()–>syncWithoutDetaching([1, 2, 3]);
I think they do the same thing, am I correct?
1, 2, 3before runningsyncWithoutDetachingthen see what the table looks like? did you then after that runattachand look at the pivot table? as that would answer this for yousyncWithoutDetachingadd new records or not? didattachadd new records or not? runsyncWithoutDetaching5 times, are there 5 times as many new records? runattach5 times, are there 5 times more records?