Insert related models when working with many-to-many relations
No array parameter is expected
Example:
$user = User::find(1);
$user->roles()->attach(1);
sync():
Similar to the attach() method, the sync() method is used to attach related models. However, the main differences are:
sync() accepts an array of IDs to place on the pivot table
Secondly, most important, the sync method will delete the data from the pivot table if the model does not exist in the array, and insert only the new items to the pivot table.