【发布时间】:2020-02-18 11:11:42
【问题描述】:
我实际上在 Laravel 5.8 上使用 nwidart/laravel-modules,但我遇到了一些路由问题。
我创建了一些模块(module_1、module_2、module_3)。
每个模块都有文件web.php,在这些文件中,我添加了以下几行:
module_1 web.php:
Route::domain('module1.domain.com')->group(function(){
Route::get('/', 'ModuleOneController@index')->name('home');
});
module_2 web.php:
Route::domain('module2.domain.com')->group(function(){
Route::get('/', 'ModuleTwoController@index')->name('home');
});
module_3 web.php:
Route::domain('module3.domain.com')->group(function(){
Route::get('/', 'ModuleThreeController@index')->name('home');
});
在我的主要 web.php 中的 laravel 项目中:
Route::domain('domain.com')->group(function(){
Route::get('/', 'HomeController@index')->name('home');
});
我可以访问这些 url 并且在每个子域上调用每个控制器,但是当我想调用函数 route('home') 时,如果我在不同域中指定每个路由名称,它总是返回 https://module3.domain.com 事件。
我想得到:
route('home') => 'https://module1.domain.com' 当我在 module1.domain.com 中调用它时
route('home') => 'https://module2.domain.com' 当我在module2.domain.com 中调用它时
等等……
有没有办法在不同的域中调用相同的路由名称并获取 不同的结果?
提前致谢
【问题讨论】: