Change Created_At Format Using Accessor In Laravel

Hello Laravel lover, in this tutorial i will show you how to change default datetime that means created_at and updated_at format in Laravel. To change this format we will use Laravel accessors. Sometimes we need to change created_at format in Laravel. So in this example i will share the code of how to change datetime created_at format in Laravel

Any model just use this code in your model class. You can change it whatever you want like how to get only date from created at in laravel.


public function getCreatedAtFormattedAttribute()
   return $this->created_at->format('H:i d, M Y');


Now 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. Hope it can help you.


#laravel #laravel-8x