mardi 22 octobre 2019

How to create same route name for differents subdomains in Laravel?

I'm actually using nwidart/laravel-modules on Laravel 5.8 and I got problem with some routes.

I created some modules (module_1, module_2, module_3).

Each module has file web.php, and in these files, I added these lines:

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');
});

And in my main web.php in laravel project:

Route::domain('domain.com')->group(function(){
    Route::get('/', 'HomeController@index')->name('home');
});

I can access to these urls and each controllers are called on each subdomains, but when I want to call the function route('home'), it always returns https://module3.domain.com event if I specified each room names in different domain.

I would to get:

route('home') => 'https://module1.domain.com' when I call it in module1.domain.com

route('home') => 'https://module2.domain.com' when I call it in module2.domain.com etc...

Is there a way to call the same route name in different domain and get differents urls ?

Thank in advance



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire