Laravel - diffForHumans 英文版

Laravel - diffForHumans in German

我正在尝试在 laravel 5.2.

中使用德语的 Carbon diffForHumans() 显示 created_at 属性 created_at 在数据库中存储为:2017-03-29 17:31:52

型号

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".

风景

@foreach($posts as $post)
    <small>{{ $post->getCreatedAtAttribute($post->created_at) }}</small>
@endforeach

错误

DateTime::__construct(): Failed to parse time string (vor 3 Tagen) at position 0 (v): The timezone could not be found in the database


如果能提供任何帮助,我将不胜感激!

对于德语翻译,我在 AppServiceProvider 中使用了此自定义:

class AppServiceProvider extends ServiceProvider
{
    public function boot()
    {
        // Localization Carbon

        \Carbon\Carbon::setLocale(config('app.locale'));
    }
}

使用此设置显示数据:vor 3 Tagen 而不是 3 days ago