1 year agoby Ajinkya shivaji pawar

laravel sync and attach detach and toggle

Dear Sarthak sir Please explain the three sync attach and toggle difference ...


Sarthak Shrivastava replied 1 year ago


  1. sync and attach are used to associate many-to-many relationships. sync accept IDs of table you want to associate and any IDs that are not in the given array will be removed from the intermediate table.
  1. toggle Toggle means if true then make it false, and if false then make it true. It Just turn the last state. So in the many-to-many relationship also provides a toggle method which "toggles" the attachment status of the given IDs. If the given ID is currently attached, it will be detached. Likewise, if it is currently detached, it will be attached.
Ask Question
Most Visited