mohammad hayajneh
mohammad hayajneh

Reputation: 37

Class translator does not exist when using app()->setLocale() in app service provider

I'm trying to use localization in my Laravel 5.8 application. Following up with this How To Build An Efficient and SEO Friendly Multilingual Architecture For Your Laravel Application I have always do the same steps and have no problems. However, when I try it with Laravel 5.8 I keep getting Class translator does not exist from app()->setLocale(request()->segment(1)); I use that in the app service provider for some reason.

AppServiceProvider

<!-- language: php -->

public function register()
{
    app()->setLocale(request()->segment(1));

    Schema::defaultStringLength(191);
}

Upvotes: 1

Views: 1786

Answers (1)

nakov
nakov

Reputation: 14288

The register method is not to be used for using services.

Try adding your code in the boot method of the class.

Also I believe a better place for adding this is in a middleware then in the service provider.

Upvotes: 1

Related Questions