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

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

  $category->books->detach([17, 22]);

  $category->books->attach([16, 23 => ['notes' => 'be careful next time...']])

From

Cover of Learning Laravel's Eloquent

Note

multiple attach and detach