简体   繁体   中英

My subdomain routes are overwriting my normal web routes in laravel 7

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM