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

报告相同问题?