Subdomain Base Without URI , Unable to catch base

2019-08-30 04:20发布

问题:

Route::domain('{account}.myapp.com')->group(function () {
 Route::get('/', function ($account) {
  dd("Cant hit this area");
 });
 Route::get('/test', function ($account) {
  dd("No problem reaching this area");
 });
});

When I visit my subdomain e.g. test.myapp.com it won't hit that DD but if say I do a /test and visit it, it would work.

I tried doing Route::get(' ' too , leaving it empty but it just wouldn't catch the base subdomain.

My Apache Conf : ServerAlias *.example.com

Ref : https://laravel.com/docs/5.8/routing#route-group-sub-domain-routing

Update

I also tried this, couldn't get it to execute

Route::group(['domain' => '{account}.example.co'], function () {
    Route::get('/', function ($account) {
        dd("HIT");
    });
});

回答1:

Found the solution.

Basically, I had this above the code I posted

Route::get('/', ['uses' => 'MainController@home']);

It was overwriting my current route. I shifted my code above this code so it doesn't get overwritten by it.