Laravel - 自定义时间戳列名称
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/25010435/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Laravel - custom timestamp column names
提问by Gravy
I am migrating a site from codeigniter to Laravel.
我正在将一个站点从 codeigniter 迁移到 Laravel。
For a legacy table reports
, some existing columns created_at
and updated_at
are named date_created
and date_modified
respectively.
对于旧表reports
,一些现有的列created_at
和updated_at
分别命名为date_created
和date_modified
。
I wish to tell my eloquent Report
model about these custom timestamp column names.
我想告诉我Report
关于这些自定义时间戳列名称的雄辩模型。
The documentation only provide reference to turning timestamps off or providing custom timestamp formats.
该文档仅提供关闭时间戳或提供自定义时间戳格式的参考。
回答by Arun Kumar
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
或者使用你可以使用这样的东西管理时间戳