laravel路由通过动态子域和不具有子域的分组

时间:2019-06-26 11:06:56

标签: laravel multi-tenant laravel-5.6

我正在hyn多租户(https://laravel-tenancy.com/的支持下,开发laravel多租户应用程序, 如果网址是“ http://domain.test”,那么我想显示我的主页;如果在laravel5.6中网址是“ http://tenant.domain.test”,则我要显示用户(每个用户的动态名称)首页。

我尝试过

//enter to this group if subdomain is present and show user homepage

    Route::domain('{tenant}.domain.test')->group(function () {
        Route::get('/', 'HomePage');
        Auth::routes();
    });

//else show main homepage

    Route::domain('domain.test')->group(function () {
        Route::get('/', 'HomePage');
    });

但是问题在于,这要求在每个视图中传递{subdomain}的值,否则会得到类似

的错误
  

缺少[路由:登录] [URI:登录]所需的参数。

1 个答案:

答案 0 :(得分:0)

Route::domain(checkDomain())->group(function () {
    Route::get('/', function () {
        return "You are on a custom domain";
    });
});

Route::get('/', function () {
     return "You are on main domain.";
});

public function checkDomain()
{
    if (request()->getHttpHost() == 'domain.test') {
        return request()->getHttpHost();
    }
}
相关问题