Using DB::raw("CURRENT_TIMESTAMP")
To set the CURRENT_TIMESTAMP you can call it within the DB::raw() method like below.
<?php $table->timestamp('created_at')->default(DB::raw('CURRENT_TIMESTAMP'));
Using useCurrent
Another approach is also using the "useCurrent()" method and this will set the default value to the CURRENT_TIMESTAMP.
<?php /* For Create */ $table->timestamp('created_at')->useCurrent(); /* For Update */ $table->timestamp('updated_at')->useCurrent()->useCurrentOnUpdate();
Leave a reply