Posts Learn Components Snippets Categories Tags Tools About

How to Set Timestamp Column to the Current Timestamp In Laravel 8 Migrations?

Learn how to set the timestamp columns (published_at or added_at) column to the current timestamp in laravel 8 through the migration file.

Created on Oct 22, 2021


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 useCurrent

Another approach is also using the "useCurrent()" method and this will set the default value to the CURRENT_TIMESTAMP.

/* For Create */

/* For Update */

If you like our tutorial, do make sure to support us by being our Patreon or buy us some coffee ☕️