web.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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. return ProductController::category($slug);
  35. } else {
  36. $page = SitePage::where('status', '1')->where('dist_id', getDistId())->where('slug', $slug)->first();
  37. if ($page) {
  38. return PageController::detail($page);
  39. }
  40. }
  41. });
  42. Route::get('/produto/{slug}', function ($slug) {
  43. return ProductController::detail($slug);
  44. });
  45. }
  46. Route::get('/demo', [DemoController::class, 'index'])->name('demo');
  47. // 主页
  48. Route::get('/', [HomeController::class, 'index'])->name('home');
  49. // 产品路由
  50. Route::prefix('products')->group(function () {
  51. Route::get('/', [ProductController::class, 'index'])->name('products.index');
  52. Route::get('/{id}', [ProductController::class, 'detail'])->name('products.detail');
  53. Route::get('/categories/{categoryId}', [ProductController::class, 'category'])->name('products.category');
  54. });
  55. // 视频路由
  56. Route::prefix('videos')->group(function () {
  57. Route::get('/', [VideoController::class, 'index'])->name('videos.index');
  58. Route::get('/{id}', [VideoController::class, 'detail'])->name('videos.detail');
  59. Route::get('/categories/{categoryId}', [VideoController::class, 'category'])->name('videos.category');
  60. });
  61. // 文章路由
  62. Route::prefix('pages')->group(function () {
  63. Route::get('/', [PageController::class, 'list'])->name('page.list'); // 页面列表页
  64. Route::get('/{slug}', [PageController::class, 'detail'])->name('page.detail'); // 页面详情页
  65. });
  66. ////专题路由,于用文章
  67. //Route::get('/collections/{slug}', [CollectionController::class, 'show'])->name('collections.show');
  68. //
  69. // 询盘路由
  70. Route::prefix('contact')->group(function () {
  71. Route::get('/', [ContactController::class, 'create'])->name('contact.create');
  72. Route::post('/', [ContactController::class, 'store'])->name('contact.store');
  73. });
  74. Route::prefix('collections')->group(function () {
  75. Route::get('/{slug}', [CollectionController::class, 'detail'])->name('collection.detail');
  76. });
  77. // Sitemap 路由
  78. Route::get('/sitemap.xml', [SitemapController::class, 'index'])->name('sitemap.index');