I
I
Ilyas Masirov2015-05-04 10:49:16
Laravel
Ilyas Masirov, 2015-05-04 10:49:16

How to make Laravel 5 trigger locale switching in AppServiceProvider.php?

Hello dear people!
I am interested in one interesting thing in Laravel 5. In the structure of the framework in the Http / Providers folder there is AppServiceProvider.php, in the boot method I write

public function boot()
{
  View::share('news_category', NewsCategory::all());
}

The NewsCategory.php model has localization:
private $locale;

    public function __construct()
    {
        $this->locale = LaravelLocalization::getCurrentLocale();
    }

   public function getNameAttribute()
    {
        $column = "name_" . $this->locale;
        return $this->{$column};
    }

So when I click on the language selector, the part that is in the news selection widget by category is not translated into another language, although it works in other models that are not located in this service provider. The question arises why?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ilyas Masirov, 2015-05-06
@Ilyas Masirov

Understood this issue. Everything turns out to be simply solved with the help of composers.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question