Best way to get locale time in my language in whole admin (backend) section?
Hello,
I'm new to Laravel 5 (and to OOP in general) and I'm trying to switch from my old procedural code.
In the whole admin (backend) section, I need to set the locale time to Italian; so far, I set 'locale' => 'it' in config/app.php and changed the routes.php file like this:
Route::group(['prefix' => 'admin'], function(){
setlocale(LC_TIME, config('app.locale'));
// here go all my routes
});
It works, but is this a correct approach (I mean, set a config in routes file)? Is there some more elegant way to keep routes separated from custom configs? Or is it better to keep simplicity like this?
Thanks a lot
If you do this with time, it will lead to loss of data integrity when you set or update a timestamp, and later change the time and set or update another. How do you know how much time passed between them?
The application needs to have one, default, timezone, and then you can use the Carbon library to display the time differently depending on the user's locale.
If you always want the text to be in Italian in the admin section (Not backend, that is something else), why not just write it in Italian? You can use the Localization feature if you want to use multi-lingual text.
@ivanhalen what I meant before was that you need to have one timezone in your application, and then when you print (Display) the time in your view layer you can change it depending on the user's timezone. A tool I can recommend that can do this is Carbon, the one that I linked above.