title: Grouping all the laravel application routes using dynamic prefix
body: <p>We have multiple client portal each one has a unique url like</p>
  
  <ul>
  <li>xyz.com/ClientPotal123</li>
  <li>xyz.com/ClientPotal234</li>
  <li>xyz.com/ClientPotalXXX</li>
  </ul>
  
  <p>We will be routing all these url's to </p>
  
  <blockquote>
    <p>/var/www/html/Laravelapp/public</p>
  </blockquote>
  
  <p>Laravelapp is our codebase which we use for all the clients.</p>
  
  <p>Since ClientPotalXXX is dynamic and unique for all the clients, I need to get the value of ClientPotalXXX for loading client specific settings like url generation, database connection (We have different database for each client).</p>
  
  <p>To achieve above I've done below changes..</p>
  
  <p>My <strong>Web.php</strong> file is as below..</p>
  
  <pre><code>Route::pattern('ClientPortal','^ClientPortal([0-9]+)?');
  Route::prefix('/{ClientPortal}')-&gt;group(function () {
      Route::get('/user/list', 'UserController@list')-&gt;name('list');
      Route::get('/user/edit/{id}', 'UserController@edit');
  });
  </code></pre>
  
  <p>I've created <strong>Middleware</strong> with below code written in it..</p>
  
  <pre><code>public function handle($request, Closure $next)
  {
      $database_name = strtolower($request-&gt;ClientPortal).'_db';
      config(['database.connections.mysql.database'=&gt;$database_name]);
      config(['app_settings.client'=&gt;$request-&gt;ClientPortal]);
      return $next($request);
  }
  </code></pre>
  
  <p>And it's working fine but previously I used to access <strong>$id</strong> in <strong>edit</strong> function directly </p>
  
  <pre><code>public function edit($id){
      echo $id; // 12
  }
  </code></pre>
  
  <p>But now $id return the value of ClientPortalXX everytime.</p>
  
  <p>If I access id from Request it works fine</p>
  
  <pre><code>public function edit(Request $request){
      $id = $request-&gt;id; // 12
  } 
  </code></pre>
  
  <p>This is happening with all of the other routes where I'm using route parameters.</p>
  
  <p>So I'm not sure if this happened because I'm using dynamic prefix for grouping all the routes? 
  And now for every <strong>route()</strong> method which I've used in blade files for url generation I have to pass the second parameter ie. Value of {ClientPortal}</p>
  
  <pre><code>{{route('register',['ClientPortal'=&gt;config('app_settings.client')])}}
  </code></pre>
  
  <p>Is this right implementation? I know we can make any varibale accessible globally using service provider but will it be right to do so?</p>
  
  <p>My Laravel Version is 5.5.xx.. I'm just a beginner so any Help/Suggestion/Advice will be appreciated Thanks :) </p>
  
  <p><strong>Update:</strong>
   Nikola Gavric and Oluwafemi Sule had already clarified my doubt in comments below.</p>
  
  <p>But since the group prefix is dynamic, How do I handle the route naming case? 
  If I had to generate user list url using list route name which is mentioned in above web.php file.</p>
  
  <p>Now I've to change this line..</p>
  
  <pre><code> {{ route('list') }}
  </code></pre>
  
  <p>To </p>
  
  <pre><code> {{ route('list',['ClientPortal'=&gt; 'ClientPortalXXX' ]) }}
  </code></pre>
  
  <p>Since prefix is also a route param. 
  Is this feasible option? Because I've to do this change everywhere where I've used route method for url generation.</p>