PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Sunday, January 30, 2022

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

 January 30, 2022     laravel-5, php, routes     No comments   

Issue

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 route 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 results ?

Thank in advance


Solution

Route::group(['domain' => 'module.domain.com'], function (){
    Route::post('login', [
        'as' => 'login',
        'uses' => 'AuthController@login'
    ]);
    // ... all route
});

Route::group(['domain' => 'module1.domain.com'], function (){        
    // ... all route
});


Answered By - Nick
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing