Class 在应用服务提供者中使用 app()->setLocale() 时翻译器不存在
Class translator does not exist when using app()->setLocale() in app service provider
我正在尝试在我的 Laravel 5.8 应用程序中使用本地化。跟进此 How To Build An Efficient and SEO Friendly Multilingual Architecture For Your Laravel Application 我总是执行相同的步骤并且没有问题。但是,当我尝试使用 Laravel 5.8 时,我不断收到 Class translator does not exist from app()->setLocale(request()->segment(1));
我出于某种原因在应用程序服务提供商中使用了它。
AppServiceProvider
<!-- language: php -->
public function register()
{
app()->setLocale(request()->segment(1));
Schema::defaultStringLength(191);
}
register
方法不能用于使用服务。
尝试在 class 的 boot
方法中添加您的代码。
此外,我认为添加它的更好位置是在中间件中,然后在服务提供商中。
我正在尝试在我的 Laravel 5.8 应用程序中使用本地化。跟进此 How To Build An Efficient and SEO Friendly Multilingual Architecture For Your Laravel Application 我总是执行相同的步骤并且没有问题。但是,当我尝试使用 Laravel 5.8 时,我不断收到 Class translator does not exist from app()->setLocale(request()->segment(1));
我出于某种原因在应用程序服务提供商中使用了它。
AppServiceProvider
<!-- language: php -->
public function register()
{
app()->setLocale(request()->segment(1));
Schema::defaultStringLength(191);
}
register
方法不能用于使用服务。
尝试在 class 的 boot
方法中添加您的代码。
此外,我认为添加它的更好位置是在中间件中,然后在服务提供商中。