Home / Snippets / Set Default Timestamp in Laravel Migration
Set Default Timestamp in Laravel Migration cover

Set Default Timestamp in Laravel Migration

187

3 years ago

0 comments

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();
});
notion avatar

Alaz

Week-end developer currently experimenting with web, mobile, and all things programming.

Topics:

Frontend

Resource

Average

Average

Support Us

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

Welcome to PostSrc V3

PostSrc Dark Logo

You have to login to favorite this