How to change created at and updated_at column name in Laravel 5?

If you want to change default column name of created_at and updated_at in your database then you are a right place. Sometime, we require to change column name because it is require when we migrate over project from codeigniter to laravel or core php to laravel etc. At that moment old developer take column name like creation_date, create_date, post_date etc as he know better name hahaha. But you require to keep on your new laravel 5.5 application instead of created_at and updated_at then you can do it.

As we know laravel framework gives automatically take current timestamps in created_at and updated_at, So here we change for other two column like "creation_date" and "update_date" column. So here for example i take my "TagList" model and i will change following column name using const keyword like as bellow:

const CREATED_AT = 'creation_date';

const UPDATED_AT = 'update_date';

Let's see bellow model code for change default column name of created_at and update_at.

Product Model:


namespace App;

use Illuminate\Database\Eloquent\Model;

class Product extends Model


public $table = "products";

public $fillable = ['name'];

const CREATED_AT = 'creation_date';

const UPDATED_AT = 'update_date';


As above model, you can define using const keyword.

I hope you found your best solution....

November 18, 2017 | 704 Viewer | Category : PHP Laravel
Related Posts