我正在构建一个子域指向用户的应用程序。如何在路由之外的其他地方获取地址的子域部分?
Route::group(array('domain' => '{subdomain}.project.dev'), function() {
Route::get('foo', function($subdomain) {
// Here I can access $subdomain
});
// How can I get $subdomain here?
});
不过,我已经建立了一个混乱的解决方法:
Route::bind('subdomain', function($subdomain) {
// Use IoC to store the variable for use anywhere
App::bindIf('subdomain', function($app) use($subdomain) {
return $subdomain;
});
// We are technically replacing the subdomain-variable
// However, we don't need to change it
return $subdomain;
});
我想在路由之外使用变量的原因是基于该变量建立数据库连接。