In this episode, we're giving our dates a glow-up! Right now, our app is just dumping out the full created_at
date and time, which can be a bit much and not super user-friendly. We're going to clean that up by building a handy method that formats dates in a nicer, more readable way.
Here's the plan: We'll add a method (we're calling it createdAtHuman
, but feel free to name it whatever makes sense for you) that will return either today
, yesterday
, or, if it's older, just the date. We'll still include the time for all of them, but we'll bump up the readability a bit.
You'll see us use PHP's match
statement along with Carbon to figure out if the date is today, yesterday, or something else. We'll make sure the output only shows the time up to the minute (no unnecessary seconds), giving us a clean look like today 14:36
instead of dumping the whole timestamp.
Finally, we'll check out the updated message list to make sure the new formatting works as expected. It's a small but effective way to make your app feel a little more polished for the user!