1
votes

Hello devs I have a project of laravel 7 in which I am trying to use sub-domain routes and I am able to do that but after adding subdomain routes I am facing an issue in which it is prefixing the subdomain in all the routes

This is the subdomain route


Route::domain('demo.'.config('app.domain'))->group(function () {
    Route::name('demo.')->group(function () {
        Route::get('/', 'DemoController@index')->name('index');
    });
});

This is the main route (web.php)


Route::group([], function() {
    Route::get('/', 'FrontController@index')->name('index');
    Route::get('/about-us', 'FrontController@about')->name('about-us');
    Route::get('/contact-us', 'FrontController@contact')->name('contact-us');
    // More routes.....
});

But when I am calling the main (web.php) routes it is applying the subdomain as the main domain

Example

<a href="{{ currentRouteIs('index') ? '#hero' : route('index') }}">Home</a>
<a href="{{ route('about-us') }}">About Us</a>
<a href="{{ route('contact-us') }}">Contact Us</a>

It needs to show the domain.com, domain.com/about-us and domain.com/contact-us but it is showing like this demo.domain.com, demo.domain.com/about-us and so on

I don't know what is the solution please help me with this.

Thank you in advance.

1

1 Answers

1
votes

Your index routes have the same name. Try altering the route name on the subdomain:

Route::domain('demo.'.config('app.domain'))->group(function () {
    Route::name('demo.')->group(function () {
        Route::get('/', 'DemoController@index')->name('demo.index');
    });
});