'strip', 'allow_unsafe_links' => false, ]); // 萃取 TOC (簡單的正則表達式抓取 ## 標題) preg_match_all('/^##\s+(.+)$/m', $markdown, $matches); $toc = collect($matches[1])->map(function ($text) { return [ 'id' => Illuminate\Support\Str::slug($text), 'text' => $text, ]; }); // 替換內容中的 ## 標題以加入 ID 錨點 (讓左側導覽能跳轉) foreach ($toc as $item) { $content = str_replace("

{$item['text']}

", "

{$item['text']}

", $content); } return view('docs.api', [ 'content' => $content, 'toc' => $toc, 'title' => '外部系統 API 對接手冊' ]); }); Route::middleware('auth')->group(function () { // 儀表板 - 所有登入使用者皆可存取 }); // End of auth middleware group