Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create subdomain in Laravel dynamically?

In my Windows/System32/drivers/etc/hosts, I have this:

127.0.0.1   localhost
127.0.0.1   site.dev
127.0.0.1   *.site.dev

In my xampp/apache/conf/extra/httpd-vhost, I have this:

<VirtualHost site.dev>  
  DocumentRoot "C:/xampp_7/htdocs/"
  <Directory "C:/xampp_7/htdocs/">
  </Directory>
</VirtualHost>
<VirtualHost *.site.dev>  
  DocumentRoot "C:/xampp_7/htdocs/"
  <Directory "C:/xampp_7/htdocs/">
  </Directory>
</VirtualHost>

Now if I am going to run http://site.dev/project/public, It is working. I have this route command:

Route::group(['domain' => '{subdomain}.site.dev'], function($subdomain) {
    return $subdomain;
});

If I open http://sub.site.dev/startscript/public/ , I get an error of "This site can’t be reached".

The function of the program is that it can create subdirectories. Example, I have a business website. I can access/create like this.

inventory.mybusiness.com
sales.mybusiness.com
ad.mybusiness.com
like image 983
Vahn Marty Avatar asked Nov 25 '16 11:11

Vahn Marty


People also ask

How do I let PHP create subdomain automatically for each user?

We use the following code: $url=$_SERVER["REQUEST_URI"]; $account=str_replace(". yourdomain.com","",$url); This code just sets the $account variable the same as the subdomain.

How can I get subdomain name in laravel?

It can be used like this: Route::group(array('domain' => '{subdomain}. project. dev'), function() { Route::get('foo', function($subdomain) { // Here I can access $subdomain }); $subdomain = Route::input('subdomain'); });


1 Answers

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.

like image 148
Vahn Marty Avatar answered Oct 14 '22 05:10

Vahn Marty