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 cocos的js代码调用wx.createUseInfoButton问题!
  • ¥15 关于自相关函数法和周期图法实现对随机信号的功率谱估计的matlab程序运行的问题,请各位专家解答!
  • ¥15 Python程序,深度学习,有偿私
  • ¥15 扫描枪扫条形码出现问题
  • ¥35 poi合并多个word成一个新word,原word中横版没了.
  • ¥15 【火车头采集器】搜狐娱乐这种列表页网址,怎么采集?
  • ¥15 求MCSCANX 帮助
  • ¥15 机器学习训练相关模型
  • ¥15 Todesk 远程写代码 anaconda jupyter python3
  • ¥15 我的R语言提示去除连锁不平衡时clump_data报错,图片以下所示,卡了好几天了,苦恼不知道如何解决,有人帮我看看怎么解决吗?