getHttpHost(); // 安全且可靠 $uri = request()->getRequestUri(); $brHost = env('BR_HOST'); // 巴西官网域名 if ($host == $brHost) { $questionMarkPosition = strpos($uri, '?'); if ($questionMarkPosition !== false) { // 截取问号前面的部分 $uri = substr($uri, 0, $questionMarkPosition); } $segments = explode('/', $uri); if ($segments) { $slug = $segments[1]; if ($slug == 'produto') { Route::get('/produto/{slug}', [ProductController::class, 'detail'])->name('products.detail'); } else { $distInfo = DistAdminDistributor::findByDomain($brHost); $categoryId = DistProductCategory::where(function ($query) use ($slug) { $query->where('slug', $slug); }) ->where('dist_id', $distInfo->id) ->first(); if ($categoryId) { return Route::get('/{categoryId}', [ProductController::class, 'category'])->name('products.category'); } else { $page = SitePage::where('status', '1')->where('dist_id', $distInfo->id)->where('slug', $slug)->first(); if ($page) { return Route::get('/{slug}', [PageController::class, 'detail'])->name('page.detail'); } } } } } Route::get('/demo', [DemoController::class, 'index'])->name('demo'); // 主页 Route::get('/', [HomeController::class, 'index'])->name('home'); // 产品路由 Route::prefix('products')->group(function () { Route::get('/', [ProductController::class, 'index'])->name('products.index'); Route::get('/{id}', [ProductController::class, 'detail'])->name('products.detail'); Route::get('/categories/{categoryId}', [ProductController::class, 'category'])->name('products.category'); }); // 视频路由 Route::prefix('videos')->group(function () { Route::get('/', [VideoController::class, 'index'])->name('videos.index'); Route::get('/{id}', [VideoController::class, 'detail'])->name('videos.detail'); Route::get('/categories/{categoryId}', [VideoController::class, 'category'])->name('videos.category'); }); // 文章路由 Route::prefix('pages')->group(function () { Route::get('/', [PageController::class, 'list'])->name('page.list'); // 页面列表页 Route::get('/{slug}', [PageController::class, 'detail'])->name('page.detail'); // 页面详情页 }); ////专题路由,于用文章 //Route::get('/collections/{slug}', [CollectionController::class, 'show'])->name('collections.show'); // // 询盘路由 Route::prefix('contact')->group(function () { Route::get('/', [ContactController::class, 'create'])->name('contact.create'); Route::post('/', [ContactController::class, 'store'])->name('contact.store'); }); Route::prefix('collections')->group(function () { Route::get('/{slug}', [CollectionController::class, 'detail'])->name('collection.detail'); }); // Sitemap 路由 Route::get('/sitemap.xml', [SitemapController::class, 'index'])->name('sitemap.index'); // 404 路由 Route::fallback(function () { $obj = new HomeController(); return $obj->abort404(); });