Set CURRENT_TIMESTAMP as default value
To set CURRENT_TIMESTAMP as default value for a column you should use DB::raw().
$table->timestamp('created_at')->default(DB::raw('CURRENT_TIMESTAMP'));
In Laravel 5.1.25 useCurrent() can be used to modify the default value.
$table->timestamp('created_at')->useCurrent();
On a mysql database, you can use 'CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP'
$table->timestamp('updated_at')->default(DB::raw('CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP'));
To update both created_at and updated_at fields:
$table->timestamp('created_at')->default(DB::raw('CURRENT_TIMESTAMP'));$table->timestamp('updated_at')->default(DB::raw('CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP'));
Comments
0 comments
Please Sign in or Create an account to Post Comments