Summer Sale! All accounts are 50% off this week.

XanderLaravel's avatar

Carbon diffForHumans() - replace seconds with "just now"

When I use

{{ $message->created_at->diffForHumans() }}

with livewire I can see it count up in seconds until 1 minute then it changes every minute. Is there a way I can instead of the first 60 seconds say "just now" and than the minutes?

0 likes
1 reply
Niush's avatar
Niush
Best Answer
Level 51

Like this:

{{ $message->created_at->diffInSeconds() < 60 ? 'just now' : $message->created_at->diffForHumans() }}

Instead if you wanted just now only for first one second, there is built in way:

{{ $message->created_at->diffForHumans(['options' => \Carbon\Carbon::JUST_NOW]) }}
1 like

Please or to participate in this conversation.