Trying to get property 'created_at' of non-object

I want to display created_at from table / model Post. So I write this code

If I var_dump. It works
enter image description here

I want to echo this

{{$user->post->first()->created_at}}

But it went wrong enter image description here

I don't know why it is trying to get property of non object


Solution 1:

You shouldn't have to call first() on your eager loaded relationship. You can just do:

$user->post->created_at

or

$user->post()->first()->created_at