Home > OS >  Subdomain in Laravel show main page
Subdomain in Laravel show main page

Time:03-22

I have problem with routing.

I have this web.php (router):

Route::get('/', 'HomeController@index')->name('home');
Route::get('/p/{slug}', 'PageController@textPage')->name('textPage');


Route::get('/o-nas', 'PageController@aboutUs')->name('aboutUs');
Route::get('/integracja', 'PageController@integration')->name('integration');
Route::get('/jak-dzialamy', 'PageController@howWeDoing')->name('howWeDoing');
Route::get('/cennik', 'PageController@priceList')->name('priceList');
Route::get('/kontakt', 'PageController@aboutUs')->name('aboutUs');

Route::get('/rejestracja-firmy', 'RegistrationController@registrationCompany')->name('registrationCompany');
Route::get( '/rejestracja', 'RegistrationController@registrationIndividual')->name('registrationIndividual');

Route::post('/zarejestruj-firme', 'RegistrationController@registrationCompanyCreate')->name('registrationCompanyCreate');
Route::post( '/zarejestruj-uzytkownika-indywidualnego', 'RegistrationController@registrationIndividualCreate')->name('registrationIndividualCreate');
Route::get('/active-user/{token}/{userId}', 'RegistrationController@activeUser')->name('activeUser');

Route::match(['post', 'get'],'/logowanie', 'LoginUserController@login')->name('loginUser');
Route::match(['post', 'get'],'/przypomnij-haslo', 'LoginUserController@forgot')->name('forgotUserPassword');
Route::match(['post', 'get'],'/przypomnij-haslo2/{token}/{email}', 'LoginUserController@forgot2')->name('forgotUserPassword2');

Route::match(['post', 'get'],'/polec-nas', 'RecommendingController@recommending')->name('recommending');
Route::get('/polityka-prywatnosci', 'PageController@privacyPolicy')->name('privacyPolicy');

Route::get('/firma/{slug}', 'CompanyController@company')->name('company');
Route::get('/oblicz-cene', 'CompanyController@calculatePrice')->name('calculatePrice');
Route::get('/oblicz-cene-rabatu', 'CompanyController@calculateDiscountPrice')->name('calculateDiscountPrice');

Route::domain('{slug}.domain.pl')->group(function () {
    Route::get('/', 'CompanyController@company')->name('company2');
});

And CompanyController:

  public function company(string $slug, Request $request)
    {   dd('test');
}

When I use domain.pl/o-nas, domain.pl/integracja etc - it's work fine. Problem is with subdomain. When I write: companyname.domain.pl - I see my main page. Not CompanyController@company.

How can I repair it?

Please help me

CodePudding user response:

In order to ensure your subdomain routes are reachable, you should register subdomain routes before registering root domain routes. This will prevent root domain routes from overwriting subdomain routes which have the same URI path.

  • Related