如何在 Laravel 模型中的 created_at 和 updated_at 使用时间戳格式

yufei       1 年, 3 月 前       346

Laravel 模型中的 created_at 和 updated_at 使用要使用 时间戳 格式,则需要修改 3 个地方:

  1. migration 中创建表结构使用下面的内容代替 $table->timestamps();

    $table->integer('created_at');
    $table->integer('updated_at');
    
  2. 重写模型中的 getDateFormat 方法,比如

    <?php
    
        protected function getDateFormat()
        {
            return 'U';
        }
    
  3. 确保模型中的 $timestamps = true

目前尚无回复
简单教程 = 简单教程,简单编程
简单教程 是一个关于技术和学习的地方
现在注册
已注册用户请 登入
关于   |   FAQ   |   我们的愿景   |   广告投放   |  博客

  简单教程,简单编程 - IT 入门首选站

Copyright © 2013-2022 简单教程 twle.cn All Rights Reserved.