douzhouqin6223 2019-04-09 16: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 16: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条)

报告相同问题?

悬赏问题

  • ¥30 eclipse开启服务后,网页无法打开
  • ¥30 雷达辐射源信号参考模型
  • ¥15 html+css+js如何实现这样子的效果?
  • ¥15 STM32单片机自主设计
  • ¥15 如何在node.js中或者java中给wav格式的音频编码成sil格式呢
  • ¥15 不小心不正规的开发公司导致不给我们y码,
  • ¥15 我的代码无法在vc++中运行呀,错误很多
  • ¥50 求一个win系统下运行的可自动抓取arm64架构deb安装包和其依赖包的软件。
  • ¥60 fail to initialize keyboard hotkeys through kernel.0000000000
  • ¥30 ppOCRLabel导出识别结果失败