LoginSignup
4
1

More than 3 years have passed since last update.

【laravel】シーダーにtimestamp()を付する

Posted at

概要

テーブルにコードを作成する際にcreate_atupdate_atを付する方法です。
簡単なのでメモ程度にサクッと書きます。
シーダーの詳細は以下をご参考ください。
【laravel】シーディングによるレコードの追加

new DateTime()

フィールドの値へDateTime()をインスタンスします。
time()メソッドも試しましたが、timestamp()はdatetime型で作成されるため、値は入力されるものの型が合わず思うように使えませんでした。

.php
$param = [
  'area' => '沖縄',
  'created_at' => new DateTime(),
  'updated_at' => new DateTime(),
];
4
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
4
1