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条)

报告相同问题?

悬赏问题

  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料