O'Reilly logo
  • GIL EG thinks this is interesting:

$category->books->sync( [4, 8, 15, 17, 22, 42] ); $category->books->sync( [4, 8, 15, 16, 23, 42] );

From

Cover of Learning Laravel's Eloquent

Note

sync() to sync the pivot table between realted manyTomany models, only records in sync will remain, others will be detached