R
R
RNB2016-08-02 16:10:52
Laravel
RNB, 2016-08-02 16:10:52

Laravel 5.2 how to set locale correctly?

Hello!
Laravel 5.2, need to output dates in localized format.
I can't figure out how to correctly set the global locale configuration.
What I tried:
1. In app.php I put 2. I dragged an article from the database. Accordingly, Laravel created a Carbon-a instance for me to work with time. I try:'locale' => 'ru',

$article->created_at->formatLocalized('%A %d %B %Y')

Outputs:
Tuesday 02 August 2016

3. I add before the date call and get what I needsetlocale(LC_TIME, "ru_RU.UTF-8");
Tuesday 02 August 2016

Question: The date needs to be displayed in many places, each time it is bad
to put the date before the output . How in Laravel globally, according to Feng Shui, to set the locale in the right place? But set it in such a way that if you need a multilingual site, you can change it with standard Laravel tools on the fly. Thank you! setlocale

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Rikcon, 2016-08-02
@Rikcon

Carbon::setLocale(config('app.locale'));
Add web to the middleware and there will be a normal date everywhere.
Or service provider

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question