laravel 5.2, wildcard subdomains
<p>I want to have routes like this:</p>

<pre><code>john-doe.mysite.local
john-another-doe.mysite.local
</code></pre>

<p>and then pass the subdomain name to some controller@method and present the users profiles.</p>

<p>I'm using <a href="https://laravel.com/docs/master/homestead" rel="nofollow noreferrer">Laravel Homestead</a>.</p>

<p>Here's my <code>/etc/hosts</code> file from my local machine:</p>

<pre><code>....
192.168.10.10 mysite.local
192.168.10.10 *.mysite.local
....
</code></pre>

<p>and on my virtual machine the <code>/etc/nginx/sites-available/mysite.local</code> file</p>

<pre><code>server {
    listen 80;
    server_name mysite.local *.mysite.local;
    root "/home/vagrant/laravel-projects/mysite.com/public";

    index index.html index.htm index.php;

    charset utf-8;

    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }
    ....
</code></pre>

<p>If you need anything else please ask.
The main domain <code>mysite.local</code> works normally.</p>

<p>I tried following the <a href="https://laravel.com/docs/master/routing#route-group-sub-domain-routing" rel="nofollow noreferrer">documentation</a> an adding this to my <code>routes.php</code> file:</p>

<pre><code>Route::group(['domain' =&gt; '{element}.mysite.local'], function() {

    Route::get('/', function ($element) {
        dd($element);
    });

});
</code></pre>

<p>But if I go to any subdomain <code>somedomain.mysite.local</code> I get server not found.</p>

<p>It seems to me the problem is that I'm not even reaching Laravel app through the subdomain.</p>

<p>Any help is appreciated. 
I've found <a href="https://stackoverflow.com/questions/34696725/laravel-homestead-and-nginx-subdomain-wildcard">this question</a>, and tried changing <code>.local</code> to <code>.dev</code> in my <code>/etc/hosts</code> and <code>mysite.local</code> files but it didn't work. I also tried changing <code>mysite.local</code> to <code>mysite.dev</code> but it didn't work either.</p>

<p>I can't figure out what am I missing here.</p>

<p><strong>UPDATE:</strong></p>

<p>If I add <code>test.mysite.local</code> to my <code>/etc/hosts</code> file I get the same output in my browser as if I was to browse for <code>mysite.local</code>.</p>

<pre><code>....
192.168.10.10 mysite.local
192.168.10.10 test.mysite.local
192.168.10.10 *.mysite.local
....
</code></pre>

<p>Updating the <code>mysite.local</code> on virtual machine:</p>

<pre><code>...
server_name mysite.local test.mysite.local *.mysite.local;
...
</code></pre>

<p>I tried adding another route to <code>routes.php</code>:</p>

<pre><code>Route::group(['domain' =&gt; 'test.mysite.local'], function() {

    Route::get('/', function () {
        dd('you are at test subdomain');
    });

});
</code></pre>

<p>to see if it works but it doesn't, I still get the same output as if I were to navigate to <code>mysite.local</code></p>

<p><strong>ANOTHER UPDATE:</strong></p>

<p><code>/etc/hosts/</code> doesn't support wildcards so for the moment I'm using static subdomain names and will figure out how to do dynamic subdomains a bit later.</p>

<p>Also put </p>

<pre><code>Route::group(['domain' =&gt; '{element}.mysite.local'], function() {

    Route::get('/', function ($element) {
        dd($element);
    });

});
</code></pre>

<p><strong>AT THE TOP</strong> or your <code>routes.php</code> file.</p>

<p>At the moment I'm trying to redirect static subdomain to the specific controller@method. Will update this as I progress.</p>

<p><strong>UPDATE - static domain working now:</strong></p>

<p>New route:</p>

<pre><code>Route::group(['domain' =&gt; '{element}.mysite.local'], function() {

    Route::get('{path}', 'ElementController@single')-&gt;where('path', '.*');

});
</code></pre>

<p><code>ElementController.php</code></p>

<pre><code>public function single($element)
{
    //return view with information about my element
    if ( $element = Element::where('slug', $element)-&gt;first() )
    {
        return view('elements.single', compact('element'));
    }

    //redirect to mysite.local if slug doesn't exist
    return redirect(Config::get('app.url')); // points to config/app.php and find `url` parameter which should be defined in your `.env` file

}
</code></pre>

<p><strong>TODO:</strong></p>

<ul>
<li><code>slug.mysite.local/sadsadas</code> works and runs the <code>single</code> method from above, I
would prefer if it would redirect to <code>slug.mysite.local</code></li>
<li>wildcard subdomains still not working</li>
</ul>