Sunday, April 2, 2017

Laravel - diffForHumans in German

I am trying to display the created_at attribute using Carbon's diffForHumans() in German.

The model

protected $dates = ['created_at', 'updated_at'];

public static function getCreatedAtAttribute($value)
{
    Carbon::setLocale('de');
    return Carbon::parse($value, 'Europe/Berlin')->diffForHumans();
}


The view

@foreach($posts as $post)
    <small></small>
@endforeach

created_at is stored in the database as: 2017-03-29 17:31:52

The error

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


I would be very thankful for any kind of help!



via kampfkuchen

Advertisement