web.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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. use App\Models\DistAdminDistributor;
  14. /*
  15. |--------------------------------------------------------------------------
  16. | Web Routes
  17. |--------------------------------------------------------------------------
  18. |
  19. | Here is where you can register web routes for your application. These
  20. | routes are loaded by the RouteServiceProvider and all of them will
  21. | be assigned to the "web" middleware group. Make something great!
  22. |
  23. */
  24. //巴西官网专用路由
  25. $host = request()->getHttpHost(); // 安全且可靠
  26. $uri = request()->getRequestUri();
  27. $brHost = env('BR_HOST'); // 巴西官网域名
  28. if ($host == $brHost) {
  29. $segments = explode('/', $uri);
  30. if ($segments) {
  31. $slug = $segments[1];
  32. if ($slug == 'produto') {
  33. Route::get('/produto/{slug}', [ProductController::class, 'detail'])->name('products.detail');
  34. } else {
  35. $distInfo = DistAdminDistributor::findByDomain($brHost);
  36. $categoryId = DistProductCategory::where(function ($query) use ($slug) {
  37. $query->where('slug', $slug);
  38. })
  39. ->where('dist_id', $distInfo->id)
  40. ->first();
  41. if ($categoryId) {
  42. return Route::get('/{categoryId}', [ProductController::class, 'category'])->name('products.category');
  43. } else {
  44. $page = SitePage::where('status', '1')->where('dist_id', $distInfo->id)->where('slug', $slug)->first();
  45. if ($page) {
  46. return Route::get('/{slug}', [PageController::class, 'detail'])->name('page.detail');
  47. }
  48. }
  49. }
  50. }
  51. }
  52. Route::get('/demo', [DemoController::class, 'index'])->name('demo');
  53. // 主页
  54. Route::get('/', [HomeController::class, 'index'])->name('home');
  55. // 产品路由
  56. Route::prefix('products')->group(function () {
  57. Route::get('/', [ProductController::class, 'index'])->name('products.index');
  58. Route::get('/{id}', [ProductController::class, 'detail'])->name('products.detail');
  59. Route::get('/categories/{categoryId}', [ProductController::class, 'category'])->name('products.category');
  60. });
  61. // 视频路由
  62. Route::prefix('videos')->group(function () {
  63. Route::get('/', [VideoController::class, 'index'])->name('videos.index');
  64. Route::get('/{id}', [VideoController::class, 'detail'])->name('videos.detail');
  65. Route::get('/categories/{categoryId}', [VideoController::class, 'category'])->name('videos.category');
  66. });
  67. // 文章路由
  68. Route::prefix('pages')->group(function () {
  69. Route::get('/', [PageController::class, 'list'])->name('page.list'); // 页面列表页
  70. Route::get('/{slug}', [PageController::class, 'detail'])->name('page.detail'); // 页面详情页
  71. });
  72. ////专题路由,于用文章
  73. //Route::get('/collections/{slug}', [CollectionController::class, 'show'])->name('collections.show');
  74. //
  75. // 询盘路由
  76. Route::prefix('contact')->group(function () {
  77. Route::get('/', [ContactController::class, 'create'])->name('contact.create');
  78. Route::post('/', [ContactController::class, 'store'])->name('contact.store');
  79. });
  80. Route::prefix('collections')->group(function () {
  81. Route::get('/{slug}', [CollectionController::class, 'detail'])->name('collection.detail');
  82. });
  83. // Sitemap 路由
  84. Route::get('/sitemap.xml', [SitemapController::class, 'index'])->name('sitemap.index');