2

i want to make a website that each user have own subdomain in my site. but beside that, i need subdomain for manage my website.

so, what i need is:

mysite.com  ---> main web
admin.mysite.com  ---> for administrator my web
blog.mysite.com  ---> for artikel my web
member.mysite.com  ---> for main account
*.mysite.com  ---> for users

im using laravel 5.4 so, how i can write on my route?

Route::group(array('domain' => '{subdomain}.mysite.com'), function() {
    //
});

thanks before.

1 Answers1

1

Routing file should contain static subdomains first and catch all at the end. Order matters.

// mysite.com
Route::group([ 'domain' => 'mysite.com' ], function () {
    Route::get('/', 'MySiteController@home');
});

// admin.mysite.com
Route::group([ 'domain' => 'admin.mysite.com' ], function () {
    Route::get('/', 'MySiteAdminController@home');
});

// blog.mysite.com
Route::group([ 'domain' => 'blog.mysite.com' ], function () {
    Route::get('/', 'MySiteBlogController@home');
});

// user subdomains
Route::group([ 'domain' => '{account}.mysite.com' ], function () {
    Route::get('/', 'TenantController@home');
    Route::get('/user/{id}', 'TenantController@userIndex');
});

Example catch all controller

class TenantController {

    public function home($account)
    {
        return 'This is home for account '.$account;
    }

    public function userIndex($account, $id)
    {
        //
    }

}
Chris Cynarski
  • 493
  • 3
  • 9