attach(); $this->sync(); // $this->detach(); // $this->syncWithoutDetaching(); } public function attach() { $user = User::find(1); $user->roles()->attach([ 2, 3]); } public function sync() { $user = User::find(1); $user->roles()->sync([3, 2]); } public function detach() { $user = User::find(1); $user->roles()->detach(); } public function syncWithoutDetaching() { $user = User::find(1); $user->roles()->syncWithoutDetaching([1, 2, 3]); } }