Posts Learn Components Snippets Categories Tags About
/

Set Default Timestamp in Laravel Migration

Learn how to set the default timestamp in Laravel migration to auto assign the current timestamp

Created on Aug 02, 2021

14 views

When writing a migration file, you can set the default value for the timestamp column type. The options are available using the "useCurrent()" method and the value will be set as CURRENT_TIMESTAMP as the default value.
<?php

Schema::create('posts', function (Blueprint $table) {
    $table->timestamp('published_at')->useCurrent();
    $table->timestamp('created_at')->useCurrent();
    $table->timestamp('updated_at')->useCurrent();
});

Snippets by

PostSrc poster

PostSrc

Full stack developer mainly focusing on the front end side of the web. The main author of PostSrc and loves writing tutorial and guides online.

Load comments for Set Default Timestamp in Laravel Migration

new

PostSrc Code Components

Collection of Tailwind CSS components for everyone to use. Browse all of the components that's right for your project.

View Components

Other Code Snippets

More