How to change created_at and updated_at column names in Laravel

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

I hope you like this Post, Please feel free to comment below, your suggestion and problems if you face - we are here to solve your problems.

Arjun

I am Arjun from Hyderabad (India). I have been working as a software engineer from last 7+ years, and its my passion to learn new things and implement them as a practice. Aside from work, I likes gardening and spending time with pets.


DMCA.com Protection Status