Change Format Of Created_at and Updated_at

Tip given by @syofyanzuhad

To change the format of created_at you can add a method in your model like this:

1public function getCreatedAtFormattedAttribute()
2{
3 return $this->created_at->format('H:i d, M Y');
4}

So you can use it $entry->created_at_formatted when it's needed. It will return the created_at attribute like this: 04:19 23, Aug 2020.

And also for changing format of updated_at attribute, you can add this method :

1public function getUpdatedAtFormattedAttribute()
2{
3 return $this->updated_at->format('H:i d, M Y');
4}

So you can use it $entry->updated_at_formatted when it's needed. It will return the updated_at attribute like this: 04:19 23, Aug 2020.

Like our articles?

Become a Premium Member for $129/year or $29/month
What else you will get:
  • 22 courses (477 lessons, total 38 h 20 min)
  • 2 long-form tutorials (one new every week)
  • access to project repositories
  • access to private Discord