Hello!
Maybe you want to achieve this using Carbon, just convert your attrbutes to Carbon instances and use the localization feature: http://carbon.nesbot.com/docs/#api-localization
Hope it helps.
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I'm dealing with date localization in Laravel. Here is how i display date in blade.php.
Publish on {{ $post->published_at->format('F j, Y') }} //Publish on November 20, 2015
I tried with (https://github.com/jenssegers/date) to
use Jenssegers\Date\Date;
Date::setLocale('hr');
echo Date::now()->format('F j, Y'); //Studeni 20, 2015
and what bothers me is how can i reformat $post->publiched_at in blade.php to be localized
You have accessors for that: http://laravel.com/docs/5.1/eloquent-mutators#accessors-and-mutators
In your model
use Jenssegers\Date\Date;
class Post extends Model
{
public function getDates()
{
return ['published_at'];
}
public function getCreatedAtAttribute($date)
{
return new Date($date);
}
public function getUpdatedAtAttribute($date)
{
return new Date($date);
}
public function getPublishedAtAttribute($date)
{
return new Date($date);
}
}
That way your timestamps will localized to the locale key defined in the config/app.php file
config/app.php
'locale' => 'cr', // your lang
Please or to participate in this conversation.