Hello,
Please check the documentation available on https://www.phpdocx.com/documentation/cookbook/tables-of-contents (It is possible to update the TOC automatically when opening the document? section). Due to internal restrictions, MS Word doesn't allow updating automatically a DOCX when the document is opened.
If you need to update the TOC automatically, you need to use a macro or the conversion plugin with the libreoffice or msword methods:
https://www.phpdocx.com/documentation/cookbook/tables-of-contents (Generate the TOC automatically with the conversion plugin section).
About the conversion plugin, please check the documentation available on the following pages:
https://www.phpdocx.com/documentation/conversion-plugin
https://www.phpdocx.com/api-documentation/format-conversion/convert-Word-docx-into-pdf-with-PHP
To use the conversion plugin based on libreoffice and autogenerate the TOC please check the docs folder available in the package.
Regards.