Hello,
If you want to use the same approach of the addTableContents method, you can set the updateFields option as true using the docxSettings method. This option request auto-updating the TOC when opening the DOCX.
If you need to update the TOC without opening it, you can use the conversion plugin based on LibreOffice (please check the docs folder included in the package). phpdocx 9.5 also includes an option to generate TOC using the conversion plugin based on MS Word.
Regards.