To set the default timestamps you can specify the "default()" method and using "DB::raw()" to get the CURRENT_TIMESTAMP value. This method works across different database drivers MySQL, PostgreSQL and others.
To set the CURRENT_TIMESTAMP you can call it within the DB::raw() method like below.
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();