Skip to content
Yo-An Lin edited this page Jun 15, 2016 · 2 revisions

Defining timestamp columns in schema:

        $this->column('revision_created_at')
            ->timestamp()
            ->null()
            ->isa('DateTime')
            ->default(function() { 
                return new \DateTime;
            });

        $this->column('revision_updated_at')
            ->timestamp()
            ->null()
            ->isa('DateTime')
            ->default(new Raw('CURRENT_TIMESTAMP'))
            ->onUpdate(new Raw('CURRENT_TIMESTAMP'))
            ;

In MySQL, there should be only one column with default current_timestamp and on update current_timestamp, because MySQL timestamp columns doesn't accept 0000-00-00 or empty string values, be sure to set it nullable by using ->null()

Clone this wiki locally