app->singleton(NavigationManager::class, function () { return new NavigationManager(); }); $this->app->singleton(TranslationManager::class, function ($app) { return new TranslationManager(); }); } /** * Bootstrap any application services. */ public function boot(): void { // Register default themes path for Blade views (static fallback) View::addNamespace('themes', base_path('themes')); // Register Gates Gate::before(function (User $user, string $ability) { if ($user->hasPermission($ability)) { return true; } }); // Share navigation with all views View::composer('*', function ($view) { $navManager = app(NavigationManager::class); // Load DB items if not already loaded (or just always merge for now) // To avoid multiple DB calls, we could cache this or just do it once. $dbItems = NavigationItem::with(['page', 'children.page'])->whereNull('parent_id')->orderBy('order')->get(); foreach ($dbItems as $item) { $navManager->register((string)$item->id, $item->label, $item->final_url, [ 'target' => $item->target, 'order' => $item->order, 'children' => $item->children->map(fn($child) => [ 'label' => $child->label, 'url' => $child->final_url, 'target' => $child->target, ])->toArray() ]); } $view->with('navigation', $navManager->getItems()); }); } }