我正在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:登录]所需的参数。
答案 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();
}
}