title: How to generate proper links using Laravel subdomain routing?
body: <p>I am trying to add dynamic subdomain routing to a project. The problem I am having is generating links between the subdomains and the top level domain.</p>
  
  <p>First I tried creating the routes this way:</p>
  
  <pre><code>Route::get('/','MainController@getHome')-&gt;name('home');
  
  Route::group(array('domain' =&gt; '{subdomain}.localhost/public'), function() {
      Route::get('/','MainController@getHomeNew' )-&gt;name('home_mew');
  });
  </code></pre>
  
  <p>My assumption was, that generating the links in the following way would lead me to the proper route:</p>
  
  <pre><code>//I assumed this would always generate a link to the root of 'localhost/public/':
  route('home'); 
  
  //And that this would always take me to a sub domain root e.g. 'cats.localhost/public/':
  route('home_new', ['subdomain' =&gt; 'cats']); 
  </code></pre>
  
  <p>When on a top-level domain page using <em>route('home_new', ['subdomain' => 'cats']);</em> properely generates a link to 'cats.localhost/public'.</p>
  
  <p>The problem is that once I am at <em>cats.localhost/public</em> and I use <em>route('home')</em> I still get redirected to <em>cats.localhost/public</em></p>
  
  <p>So I tried wrapping the top level domain routes in a group of its own:</p>
  
  <pre><code>Route::group(array('domain' =&gt; 'localhost/public'), function() {
      Route::get('/','MainController@getHome')-&gt;name('home');
  });
  
  Route::group(array('domain' =&gt; '{subdomain}.localhost/public'), function() {
      Route::get('/','MainController@getHomeNew' )-&gt;name('home_mew');
  });
  </code></pre>
  
  <p>This however results in a 404 error regardless of whether I go to the top domain root or a subdomain root.</p>
  
  <p>How can I generate links in a subdomain that would lead to the top level domain instead? Can this be done without for example relying on redirecting?</p>