0

I have a simple L5 application, where I have to output some dates in a different language and therefore I am using jenssegers/laravel-date package

Yet, if I try to use jenssegers new package on my data stored in my database, I don't get the translation, see here:

index.blade.php

@extends('app')

@section('content')

use Jenssegers\Date\Date;
// This returns 'vor 0 Sekunden' in German, which I do want.
echo Date::now()->diffForHumans();

echo '<br/>';

// This returns '1 day ago'. It is in English, but I need it in German.
echo $orders->find(1)->created_at->diffForHumans();

@endsection

Would appreciate any help.

Gaurav Dave
  • 6,838
  • 9
  • 25
  • 39
LoveAndHappiness
  • 9,735
  • 21
  • 72
  • 106

1 Answers1

2

The reason for this to happen is that $orders->find(1)->created_at returns a Carbon instance, not a Date one.

One approach to leverage Date is by doing it:

echo Date::instance($orders->find(1)->created_at)->diffForHumans();

You can use an acessor to always return a Date object, like so:

at your Order model:

public function getCreatedAtAttribute($value)
{
    return Date::instance($value);
}
Ravan Scafi
  • 6,382
  • 2
  • 24
  • 32
  • Yes I know. I did this, which is the reason the "echo Date::now()->diffForHumans();" returns the correct translated german string. Yet the other one does not. – LoveAndHappiness Apr 15 '15 at 20:22