16
Help us understand the problem. What are the problem?

More than 5 years have passed since last update.

posted at

updated at

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

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にカラム名を追加すれば動く。

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Sign upLogin
16
Help us understand the problem. What are the problem?