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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 09:52:44  来源:igfitidea点击:

Laravel - custom timestamp column names

laraveltimestampeloquent

提问by Gravy

I am migrating a site from codeigniter to Laravel.

我正在将一个站点从 codeigniter 迁移到 Laravel。

For a legacy table reports, some existing columns created_atand updated_atare named date_createdand date_modifiedrespectively.

对于旧表reports,一些现有的列created_atupdated_at分别命名为date_createddate_modified

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

我想告诉我Report关于这些自定义时间戳列名称的雄辩模型。

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

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

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

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

回答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

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