$subdomain is injected into the actual Route callback, it is undefined inside the group closure because Request has not yet been parsed.
I donβt understand why you need to have it inside the closure of the BUT group outside the actual Route callback.
If you want it to be available everywhere, ONLY after Request been parsed, you can configure the filter after saving the value of $subdomain :
Config::set('request.subdomain', Route::getCurrentRoute()->getParameter('subdomain'));
Refresh : apply a group filter to configure the connection to the database.
Route::filter('set_subdomain_db', function($route, $request) { //set your $db here based on $route or $request information. //set it to a config for example, so it si available in all //the routes this filter is applied to Config::set('request.subdomain', 'subdomain_here'); Config::set('request.db', 'db_conn_here'); }); Route::group(array( 'domain' => '{subdomain}.project.dev', 'before' => 'set_subdomain_db' ), function() { Route::get('foo', function() { Config::get('request.subdomain'); }); Route::get('bar', function() { Config::get('request.subdomain'); Config::get('request.db'); }); });
source share