Adventures in learning Tailwind, Alpine, Laravel and Livewire
19 Jan, 2021
So, if you’re displaying something like posts or tasks on your site and you want to know how long ago they were created, then you’ll probably be pulling back the created_at date with something like this:
{{ $task->created_at }}
and it comes out on your page looking like this:
2019-09-11 10:26:21
If you’d prefer to show something more user-friendly then use Carbon (which is already in Laravel):
{{ $task->created_at->diffForHumans() }}
and instead you’ll get:
1 week ago
For more information about all the wonderful things you can do with Carbon, go here: Carbon.