LoginSignup
24
15

More than 5 years have passed since last update.

Laravelで独自で設定したタイムスタンプのときに->format('Y-m-d');が使えなかった時

Last updated at Posted at 2016-11-15

Laravelで日付のフォーマットがCall to a member function format() on stringで動かない

echo $value->traded_day->format('Y-m-d');
だとか
{{$value->traded_day->format('Y-m-d');}}
が動かない時。

モデル名.php
class モデル名 extends Model
{
    use SoftDeletes;

    protected $dates = [
        'traded_day', //追加する。
        'created_at',
        'updated_at',
        'deleted_at'
    ];

作成したModelでdatesにカラム名を追加すれば動く。

24
15
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
24
15