title: Laravel 5, Sub-Domain routing, with optional parameter
body: <p>I’ve just started learning Laravel 5 and trying to create multilanguage web site and want to use different domains for the language so en.example.app points to English version, es.example.app to Spanish and so on. I use route groups and below is my code.</p>
  
  <pre><code>Route::group(['domain' =&gt; '{domain}.example.app'], function() {
      Route::get('/', function () {
          return view('index');
      });
      Route::get('test', function(){
          return view('index');
      });
  });
  </code></pre>
  
  <p>It works fine for all domains except example.app. Unfortunately optional parameters {domain?} doesn’t work for subdomains, and I don’t want to duplicate routes like this.</p>
  
  <pre><code>Route::get('/', function () {
      return view('index');
  });
  Route::get('test', function(){
      return view('index');
  });
  
  Route::group(['domain' =&gt; '{domain}.example.app'], function() {
      Route::get('/', function () {
          return view('index');
      });
      Route::get('test', function(){
          return view('index');
      });
  });
  </code></pre>
  
  <p>Could somebody please advise how to avoid this duplication?</p>