map(function ($route) { if (str_starts_with($route->uri(), 'api/')) { return [ 'method' => $route->methods()[0] === 'HEAD' ? 'GET' : $route->methods()[0], 'path' => '/' . $route->uri(), ]; } return null; })->filter()->unique('path')->sortBy('path')->values(); return view('api-endpoints', compact('routes')); } public function showDocs() { $path = base_path('API.md'); if (!file_exists($path) || !is_readable($path)) { $content = '
API documentation file not found.
'; return view('api-docs', compact('content')); } $markdown = file_get_contents($path); $content = Str::markdown($markdown); $tocMap = []; preg_match_all('/-\s+\[(.+?)\]\(#(.+?)\)/', $markdown, $matches, PREG_SET_ORDER); foreach ($matches as $m) { $tocMap[trim($m[1])] = $m[2]; } $content = preg_replace_callback( '/(.*?)<\/h\1>/i', function ($m) use ($tocMap) { $level = $m[1]; $inner = $m[2]; $text = trim(strip_tags(html_entity_decode($inner))); $id = $tocMap[$text] ?? Str::slug($text); return sprintf('%s', $level, $id, $inner, $level); }, $content ); return view('api-docs', compact('content')); } }