Skip to content

How to change created_at and updated_at column names in Laravel

Last updated on February 17, 2018

You can easily change created_at and updated_at column names by overriding CREATED_AT and UPDATED_AT constants in your Eloquent model.

Example #Task Model

Let’s assume you have a model called Task and it has columns called createdAt and updatedAt. But Laravel tries to insert data created_at and udpated_at column by default. So in order to inform Laravel about our new columns just define constants in your eloquent model as shown below –


Now Laravel will use above defined columns instead of created_at and updated_at columns.

Here is Eloquent base model - https://github.com/illuminate/database/blob/5.5/Eloquent/Model.php

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Most Voted
Newest Oldest
Inline Feedbacks
View all comments