douzhouqin6223 2019-04-09 08:30
浏览 228
已采纳

如何获取日期并将其插入到使用Laravel的php中[关闭]

I want to know how can I make Laravel to get the current date and insert it into the database with the rest of the data from a form.

Thanks in advance.

  • 写回答

3条回答 默认 最新

  • dongtingxiao4697 2019-04-09 08:37
    关注

    Laravel comes with this functionality out of the box.

    You can add this code to your migration:

    $table->timestamps();
    

    This will create a created_at and updated_at field in your database which are automatically filled.


    Or if you want to don't want to do it within Laravel, you can do one of these:

    • Set the default value of the column to: TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
    • Assign the value in the controller: $model->created_at = date('Y-m-d'); and save it normally.
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部