skip to Main Content

I have set up my subdomain domain routes like this:-

Route::group(['domain' => '{subdomain}.' . env('APP_URL'), 'prefix' => 'console', 'namespace' => 'admin', 'middleware' => 'subdomain'], function () {
   Route::get('/login', 'LoginController@index')->name('admin.login');
});

And main domain routes like this-

Route::group(['prefix' => 'console', 'namespace' => 'admin', 'middleware' => 'maindomain'], function () {
    Route::get('/login', 'LoginController@index')->name('admin.login');
});

Now in an email, I want to send the login url of the subdomain.

  1. If I simply write route('admin.login') it will give me the login
    url of the main domain.
  2. url() . 'console/login' will also give me
    the login url of the main domain.

How can I get/print the login url of the subdomain?

2

Answers


  1. url() or route() or secure_url() all create the full url based on the domain the request is coming from. For example if you hit your controller route from main domain your url will be made with main domain and if you hit your url from subdomain urls will be created with subdomain.
    You will have to achieve this manually if both your domains are directing to same project folder.

    Login or Signup to reply.
  2. To access subdomain-route use this

    route('admin.login','subdomain') // `subdomain` that you defined in Route
    

    Point to Note :-

    As per official docs you need to register subdomain-routes before registering root domain-routes. This will prevent root domain routes from overwriting subdomain routes which have the same URI path.

    Check the link below for detailed information–

    https://laravel.com/docs/11.x/routing#route-group-subdomain-routing

    Try this ,It will resolve the issue.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search