How to generate Tabel of Contents

Add Table of Contents to your blog post.

Install package

https://github.com/caseyamcl/toc

composer require caseyamcl/toc

How to use it

$markupFixer  = new \TOC\MarkupFixer();
$tocGenerator = new \TOC\TocGenerator();

$body  = "<div class='content'>" . $markupFixer->fix($guidePost->body) . "</div>";
$toc   = "<div class='toc'>" . $tocGenerator->getHtmlMenu($body) . "</div>";

View

{!! $toc !!}
{!! $body !!}
;