1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Laravelでレコード生成、更新時に自動更新されるタイムスタンプをミリ秒にする

Posted at

概要

Laravelでレコード生成、更新時に自動更新されるタイムスタンプをミリ秒にする。

実装

モデルクラス
class モデル名 extends Model
{
    // このメソッドをオーバーライドする
    public function getDateFormat()
    {
        return 'Y-m-d H:i:s.u';
    }
}
マイグレートクラス
class マイグレート名 extends Migration
{
    public function up()
    {
        Schema::create('table_name', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->dateTime('created_at', 6); // 精度を6にする。
            $table->dateTime('updated_at', 6); // 精度を6にする。
        });
    }
}

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?