I'm trying to display the created_at column in one of my views and I'm not having any luck. When I try using the below:
{{ date('d M Y - H:i:s', $object->created_at) }}
I get the following error: date() expects parameter 2 to be long, object given. So I use dd() on $object->created_at and it gives me this:
object(Carbon\Carbon)#555 (3) { ["date"]=> string(26) "2015-01-22 14:36:37.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(19) "Africa/Johannesburg" }
So naturally I tried accessing the date with a foreach loop which didn't work and I also tried $object->created_at->date which gave me an error "Unknown getter 'date'" How do I access the date from created_at?
Laravel uses Carbon. Then try this:
{{ date('d M Y - H:i:s', $object->created_at->timestamp) }}
Or this is the same without date function
{{ $object->created_at->format('d M Y - H:i:s') }}
Or use any method documented in the Carbon API