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.
- If I simply write
route('admin.login')
it will give me the login
url of the main domain. 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
url()
orroute()
orsecure_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.
To access
subdomain-route
use thisPoint to Note :-
As per official docs you need to register
subdomain-routes
before registering rootdomain-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.