Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are the advantages of the created_at and updated_at column in Laravel

I am new to laravel. Recently, I have created my ER diagram for my app. While learning laravel I see that they have this timestamp property in the schema builder that creates a created_at and updated_at column. Base on my modeling I don't really need these extra columns, so it's a must to have them or what are the benefits of having these columns on every table.

like image 827
Fokwa Best Avatar asked Sep 01 '15 11:09

Fokwa Best


1 Answers

A benefit for having them, in cases where you need them, is that Eloquent will automatically update these fields. So lets say you update a model, Eloquent will automatically set the updated_at, leaving you with less code to write, maintain and think about.

As it is not a requirement to have these timestamps on every table, you can simply disable them by using public $timestamps = false; on the related model as such:

class User extends Eloquent {

    protected $table = 'users';

    public $timestamps = false;

}
like image 195
Nicklas Kevin Frank Avatar answered Sep 21 '22 18:09

Nicklas Kevin Frank