web.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. <?php
  2. use Illuminate\Support\Facades\Route;
  3. use App\Http\Controllers\HomeController;
  4. use App\Http\Controllers\ProductController;
  5. use App\Http\Controllers\PageController;
  6. use App\Http\Controllers\ContactController;
  7. use App\Http\Controllers\VideoController;
  8. use App\Http\Controllers\DemoController;
  9. use App\Http\Controllers\SitemapController;
  10. use App\Http\Controllers\CollectionController;
  11. use App\Models\DistProductCategory;
  12. use App\Models\SitePage;
  13. /*
  14. |--------------------------------------------------------------------------
  15. | Web Routes
  16. |--------------------------------------------------------------------------
  17. |
  18. | Here is where you can register web routes for your application. These
  19. | routes are loaded by the RouteServiceProvider and all of them will
  20. | be assigned to the "web" middleware group. Make something great!
  21. |
  22. */
  23. //巴西官网专用路由
  24. $host = $_SERVER['HTTP_HOST']; // 获取当前域名
  25. $uri = $_SERVER['REQUEST_URI']; // 获取当前请求的URI
  26. if ($host == 'internal-demo-site.mietubl.com.cn') {
  27. $segments = explode('/', $uri);
  28. if ($segments) {
  29. $slug = $segments[0];
  30. $categoryId = DistProductCategory::where(function ($query) use ($slug) {
  31. $query->where('slug', $slug);
  32. })
  33. ->where('dist_id', getDistId())
  34. ->first();
  35. if ($categoryId) {
  36. Route::get('/{categoryId}', [ProductController::class, 'category'])->name('products.category');
  37. } else {
  38. $page = SitePage::where('status', '1')->where('dist_id', getDistId())->where('slug', $slug)->first();
  39. if ($page) {
  40. return Route::get('/{slug}', [PageController::class, 'detail'])->name('page.detail');
  41. }
  42. }
  43. }
  44. exit;
  45. Route::get('/{slug}', function ($slug) {
  46. // 查询数据库,将 category_slug 转换为对应ID
  47. });
  48. Route::get('/produto/{slug}', function ($slug) {
  49. $productController = new ProductController();
  50. return $productController->detail($slug);
  51. });
  52. }
  53. Route::get('/demo', [DemoController::class, 'index'])->name('demo');
  54. // 主页
  55. Route::get('/', [HomeController::class, 'index'])->name('home');
  56. // 产品路由
  57. Route::prefix('products')->group(function () {
  58. Route::get('/', [ProductController::class, 'index'])->name('products.index');
  59. Route::get('/{id}', [ProductController::class, 'detail'])->name('products.detail');
  60. Route::get('/categories/{categoryId}', [ProductController::class, 'category'])->name('products.category');
  61. });
  62. // 视频路由
  63. Route::prefix('videos')->group(function () {
  64. Route::get('/', [VideoController::class, 'index'])->name('videos.index');
  65. Route::get('/{id}', [VideoController::class, 'detail'])->name('videos.detail');
  66. Route::get('/categories/{categoryId}', [VideoController::class, 'category'])->name('videos.category');
  67. });
  68. // 文章路由
  69. Route::prefix('pages')->group(function () {
  70. Route::get('/', [PageController::class, 'list'])->name('page.list'); // 页面列表页
  71. Route::get('/{slug}', [PageController::class, 'detail'])->name('page.detail'); // 页面详情页
  72. });
  73. ////专题路由,于用文章
  74. //Route::get('/collections/{slug}', [CollectionController::class, 'show'])->name('collections.show');
  75. //
  76. // 询盘路由
  77. Route::prefix('contact')->group(function () {
  78. Route::get('/', [ContactController::class, 'create'])->name('contact.create');
  79. Route::post('/', [ContactController::class, 'store'])->name('contact.store');
  80. });
  81. Route::prefix('collections')->group(function () {
  82. Route::get('/{slug}', [CollectionController::class, 'detail'])->name('collection.detail');
  83. });
  84. // Sitemap 路由
  85. Route::get('/sitemap.xml', [SitemapController::class, 'index'])->name('sitemap.index');