我正在尝试在 laravel 5.2 中created_at使用 Carbon 的diffForHumans()德语显示属性。
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();
}
Run Code Online (Sandbox Code Playgroud)
dd($value);返回"2017-03-29 17:31:52"。
风景
@foreach($posts as $post)
<small>{{ $post->getCreatedAtAttribute($post->created_at) }}</small>
@endforeach
Run Code Online (Sandbox Code Playgroud)
错误
DateTime::__construct(): 无法在位置 0 (v) 解析时间字符串 (vor 3 Tagen):在数据库中找不到时区
我将非常感谢任何形式的帮助!