Laravel - 自定义时间戳列名称 [英] Laravel - custom timestamp column names

查看:330
本文介绍了Laravel - 自定义时间戳列名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



对于传统表格报告,一些现有的列 created_at updated_at 命名为 date_created date_modified



我想告诉我有口皆碑的报告自定义时间戳列名称。



该文档仅提供关闭时间戳或提供自定义时间戳格式的参考。



http://laravel.com/docs/eloquent#timestamps

解决方案

在模型中,您可以定义这样的常量来更改列名称

  class BaseModel扩展Eloquent {
const CREATED_AT ='date_created';
const UPDATED_AT ='date_modified';
}

或使用你可以使用这样的东西管理时间戳


I am migrating a site from codeigniter to Laravel.

For a legacy table reports, some existing columns created_at and updated_at are named date_created and date_modified respectively.

I wish to tell my eloquent Report model about these custom timestamp column names.

The documentation only provide reference to turning timestamps off or providing custom timestamp formats.

http://laravel.com/docs/eloquent#timestamps

解决方案

In model your can define constants like this to change the column names

class BaseModel extends Eloquent {
    const CREATED_AT = 'date_created';
    const UPDATED_AT = 'date_modified';
}

or use you can use something like this Managing Timestamps

这篇关于Laravel - 自定义时间戳列名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆