Laravel - diffForHumans in German
I am trying to show an attribute created_at
using Carbon diffForHumans()
in German in laravel 5.2. created_at
stored in the database as: 2017-03-29 17:31:52
Model
protected $dates = ['created_at', 'updated_at'];
public static function getCreatedAtAttribute($value)
{
Carbon::setLocale('de');
return Carbon::parse($value, 'Europe/Berlin')->diffForHumans();
}
dd($value);
returns "2017-03-29 17:31:52"
.
View
@foreach($posts as $post)
<small>{{ $post->getCreatedAtAttribute($post->created_at) }}</small>
@endforeach
Mistake
DateTime :: __ construct (): Failed to parse time string (vor 3 Tagen) at position 0 (v): timezone was not found in the database
I would really appreciate any help!
source to share
For German translation, I used this setting in the AppServiceProvider:
class AppServiceProvider extends ServiceProvider
{
public function boot()
{
// Localization Carbon
\Carbon\Carbon::setLocale(config('app.locale'));
}
}
With this setting, data is displayed: vor 3 Tagen
instead of 3 days ago
.
source to share