Route::currentRouteName(), // 'params' => Route::current()->parameters() // ]); // Handle route parameters correctly based on which route was matched if (Route::currentRouteName() === 'page.show') { $slug = $locale; // In 'page.show', the first parameter is the slug $locale = null; } // Handle homepage if ($slug === null || $slug === '/') { $page = Page::where('slug', 'home')->where('is_published', true)->first(); } else { $page = Page::where('slug', $slug)->where('is_published', true)->first(); } if (!$page) { if ($slug === null || $slug === '/') { return view('welcome'); } abort(404); } // Force set app locale if we have it from route (for rendering) if ($locale) { app()->setLocale($locale); } // Re-render content if locale is not default or if it's explicitly set. // This ensures multi-locale content JSON is correctly processed by PageRenderer. if ($locale && $locale !== config('app.fallback_locale', 'en')) { $renderer = new \App\Support\PageRenderer(); $page->cached_html = $renderer->render($page->content); } return view('page', [ 'page' => $page, ]); } }