doutangshuan6473 2014-07-23 06:51
浏览 147
已采纳

更新Created_at时间戳Laravel db种子

I'm running an app that processes user data entered over a period of time. For that, I need to change the timestamps in the data I use to seed the database. I have a nice loop to do it, but the problem is, when I run the database seeding, nothing happens. I'm wondering if there is a Laravel specific thing that prevents this, and if so how to get around it.

            $record->created_at = $fakeCreateDate->format('Y-m-d H:i:s');
            $record->save();
  • 写回答

2条回答 默认 最新

  • douju6850 2014-07-23 07:07
    关注

    Yes, created_at and updated_at are "special". Laravel sets the timestamp for created_at at create time and updated_at at update time.

    http://laravel.com/docs/eloquent#timestamps

    You can turn them off by doing this inside your model

    public $timestamps = false;
    

    By default, Eloquent will maintain the created_at and updated_at columns on your database table automatically. Simply add these timestamp columns to your table and Eloquent will take care of the rest. If you do not wish for Eloquent to maintain these columns, add the following property to your model

    Once a model is defined, you are ready to start retrieving and creating records in your table. Note that you will need to place updated_at and created_at columns on your table by default. If you do not wish to have these columns automatically maintained, set the $timestamps property on your model to false.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line