By default, Laravel Eloquent maintain two columns created_at
and updated_at
in your database tables automatically you just need to add these two columns in your tables and Eloquent will take care of the rest.
If you create table by following Laravel special schema builder then it create by default these two columns by using $table->timestamps();
.This is very useful sometime to deal with last edit data on a specific table
Sometime if this is not so useful and you do not want that Eloquent will maintain these two columns then you can disable it by adding following timestamp property false to your model :
- class Product extends Eloquent {
- protected $table = 'products';
- public $timestamps = false;
- }
You can check if it is working or not then save any record in table and see these two columns will have null value if you set timestamps property false.
If you want to disable one timestamps for updated_at only then you can write a mutator for the same column which you want to disable.
- public function setUpdatedAt($value)
- {
- // Do nothing.
- }
Same you can do with created_at column if you need to disable only created_at column.