web.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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. if ($host == 'internal-demo-site.mietubl.com.cn') {
  26. Route::get('/{slug}', function ($slug) {
  27. // 查询数据库,将 category_slug 转换为对应ID
  28. $categoryId = DistProductCategory::where(function ($query) use ($slug) {
  29. $query->where('slug', $slug);
  30. })
  31. ->where('dist_id', getDistId())
  32. ->first();
  33. if ($categoryId) {
  34. $productController = new ProductController();
  35. return $productController->category($slug);
  36. } else {
  37. $page = SitePage::where('status', '1')->where('dist_id', getDistId())->where('slug', $slug)->first();
  38. if ($page) {
  39. // $pageController = new PageController();
  40. // return $pageController->detail($page);
  41. return app()->call([PageController::class, 'detail'], ['slug' => $$slug]);
  42. }
  43. }
  44. });
  45. Route::get('/produto/{slug}', function ($slug) {
  46. $productController = new ProductController();
  47. return $productController->detail($slug);
  48. });
  49. }
  50. Route::get('/demo', [DemoController::class, 'index'])->name('demo');
  51. // 主页
  52. Route::get('/', [HomeController::class, 'index'])->name('home');
  53. // 产品路由
  54. Route::prefix('products')->group(function () {
  55. Route::get('/', [ProductController::class, 'index'])->name('products.index');
  56. Route::get('/{id}', [ProductController::class, 'detail'])->name('products.detail');
  57. Route::get('/categories/{categoryId}', [ProductController::class, 'category'])->name('products.category');
  58. });
  59. // 视频路由
  60. Route::prefix('videos')->group(function () {
  61. Route::get('/', [VideoController::class, 'index'])->name('videos.index');
  62. Route::get('/{id}', [VideoController::class, 'detail'])->name('videos.detail');
  63. Route::get('/categories/{categoryId}', [VideoController::class, 'category'])->name('videos.category');
  64. });
  65. // 文章路由
  66. Route::prefix('pages')->group(function () {
  67. Route::get('/', [PageController::class, 'list'])->name('page.list'); // 页面列表页
  68. Route::get('/{slug}', [PageController::class, 'detail'])->name('page.detail'); // 页面详情页
  69. });
  70. ////专题路由,于用文章
  71. //Route::get('/collections/{slug}', [CollectionController::class, 'show'])->name('collections.show');
  72. //
  73. // 询盘路由
  74. Route::prefix('contact')->group(function () {
  75. Route::get('/', [ContactController::class, 'create'])->name('contact.create');
  76. Route::post('/', [ContactController::class, 'store'])->name('contact.store');
  77. });
  78. Route::prefix('collections')->group(function () {
  79. Route::get('/{slug}', [CollectionController::class, 'detail'])->name('collection.detail');
  80. });
  81. // Sitemap 路由
  82. Route::get('/sitemap.xml', [SitemapController::class, 'index'])->name('sitemap.index');