加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

php – 在子域路由(Laravel)中获取子域

发布时间:2020-12-14 19:39:39 所属栏目:大数据 来源:网络整理
导读:我正在构建一个子域指向用户的应用程序.我怎样才能获得地址的子域名 – 除了路线之外的其他地址? Route::group(array('domain' = '{subdomain}.project.dev'),function() { Route::get('foo',function($subdomain) { // Here I can access $subdomain }); /
我正在构建一个子域指向用户的应用程序.我怎样才能获得地址的子域名 – 除了路线之外的其他地址?
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;

});

我想在路由之外使用变量的原因是基于该变量建立数据库连接.

Shortly after问了这个问题,Laravel实现了一种在路由代码中获取子域的新方法.它可以像这样使用:
Route::group(array('domain' => '{subdomain}.project.dev'),function($subdomain) {
        // Here I can access $subdomain
    });

    $subdomain = Route::input('subdomain');

});

请参见“访问路径参数值”in the docs.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读