@php $menusPath = view('docs.menu-data')->getPath(); $menus = include($menusPath); function flatten_menu($menus) { $flat = []; foreach ($menus as $menu) { if (isset($menu['children'])) { foreach ($menu['children'] as $child) { $flat[] = ['title' => $child['title'], 'url' => $child['url']]; } } else { $flat[] = ['title' => $menu['title'], 'url' => $menu['url']]; } } return $flat; } $flatMenus = flatten_menu($menus); $currentPath = str_replace(url('/'), '', url()->current()); $index = collect($flatMenus)->pluck('url')->search($currentPath); if ($index !== false && is_int($index)) { $prev = $index > 0 ? $flatMenus[$index - 1] : null; $next = $index < count($flatMenus) - 1 ? $flatMenus[$index + 1] : null; } else { $prev = null; $next = null; } @endphp
{!! $content !!}
@if ($prev) ← Sebelumnya: {{ $prev['title'] }} @else
{{-- Placeholder agar jarak seimbang --}} @endif @if ($next) Selanjutnya: {{ $next['title'] }} → @endif