Support the ongoing development of Laravel.io →
posted 3 years ago
Last updated 1 year ago.
0
moderator

Hello Christian,

The beauty of the accessor is that you don't need to call the function but the attribute you want to have. In your view you can use:

<p> {{ $thread->getFirstPost()->user->name }} {{ $thread->created_at }} </p>

What happen with your code is that getCreatedAtAttribute is called twice, first with the real attribute value and then with the result from the first call.

You get the error because Carbon can't parse the result from the diffForHumans to use it again.

See the docs for more information: https://laravel.com/docs/8.x/eloquent-mutators#defining-an-acc...

Last updated 3 years ago.

xdesertx liked this reply

1

worked, oh my god...

thanks.

greetings, Christian

0

Sign in to participate in this thread!

Eventy

Your banner here too?

Christian xdesertx Joined 16 Feb 2021

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.