I'm using Laravel 4 to create my project.
I am currently building the comments section and I want to display how long ago the post was created, kind of like Facebook's '10 mins ago' & '2 weeks ago' etc.
I have done a little bit of research and found that a package called Carbon can do this.
After reading the Laravel doc's, it says:
By default, Eloquent will convert the
created_at
,updated_at
, anddeleted_at
columns to instances ofCarbon
, which provides an assortment of helpful methods, and extends the native PHPDateTime
class.
But when I return a date column that I have created, it doesn't display it like on Facebook.
The code that I'm using is:
return array('time');
Has any body used this Carbon package that could give me a hand in doing what I need, I'm quite confused.
$comment->created_at
is already a Carbon object by default so all you need to do is:$bookmark->created_at->diffForHumans()
– Socher