How to create subdomain in Laravel dynamically?

I have solved it. I used Acyrlic DNS Proxy from this answer. Checkout the below link you will find the answer.

https://laracasts.com/discuss/channels/general-discussion/dynamic-sub-domain-creation-on-new-user-registration-in-laravel-5-and-wampserver

then the

Route::group(['domain' => '{account}.dns.dev'], function () {
    Route::get('/', function ($account) {
        return $account;
    });
});

is now working.


If you are planning to develop a multi-tenancy app, you can use the TenancyForLaravel library. It is easy to use and takes care of routes, tenant database etc automatically.

You can find it at https://github.com/stancl/tenancy


I am using laravel version above 5

$appRoutes = function() {
    Route::get('/',function(){
        return view('welcome');
    }); 
};

Route::group(['subdomain' => '{subdomain}.yoursitename.com'], $appRoutes );

Place this code in your route file.
But in my case, the laravel app was placed after the root so is used subdomain Route like this

   $appRoutes = function() {
        Route::get('/foldername/',function(){
            return view('welcome');
        }); 
    };

 Route::group(['subdomain' => '{subdomain}.yoursitename.com/foldername'], $appRoutes );