Laravel 8: how to manage Many-to-Many relationships with sync() method

From an Library object, we recall the relationship function and then we launch the sync( ) method, which accepts as parameters a series of ID’s, also in array form -in this case, the $request->books input-
A <select> on a website page
The contains( ) method accepts two parameters: the key to check -‘id’- and the value to find -’$book->id’-

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store