Trouble displaying created_at value in view
Asked Answered
Y

2

13

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?

Yacht answered 3/2, 2015 at 2:36 Comment(0)
E
20

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

Empanel answered 3/2, 2015 at 3:4 Comment(0)
U
4

This is another method -

{{ date('F d, Y', strtotime($list->created_at)) }}
Unattached answered 22/1, 2016 at 19:38 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.