我正在 Laravel 中构建一个网站,需要为每种语言使用不同的域。 目前我正在使用
mcamara/laravel-localization
进行本地化。
例如:
默认情况下似乎不支持使用不同的域。 有人遇到过这个问题并且知道如何解决吗?
默认支持子域名。
Route::domain('{locale}.website.com')->middleware('set-locale')->group(function () {
// your routes here
})->where('locale', '(my-english|my-dutch|my-spanish)');
您使用
where
将 {locale} 参数与正则表达式模式匹配,然后使用中间件来实际设置区域设置。
也许你的中间件中有这样的东西
public function handle(Reques $request, Closure $next)
{
$locales = ['my-english' => 'en', 'my-spanish' => 'es', ...];
app()->setLocale($locales[$this->route->parameter('locale')]);
return $next($request);
}
我不确定这是否是正确的语法,但你明白了。