Laravel - 自定义时间戳列名称 [英] Laravel - custom timestamp column names
问题描述
我正在将一个网站从 codeigniter 迁移到 Laravel.
I am migrating a site from codeigniter to Laravel.
对于旧表reports
,一些现有的列created_at
和updated_at
被命名为date_created
和date_modified
分别.
For a legacy table reports
, some existing columns created_at
and updated_at
are named date_created
and date_modified
respectively.
我想告诉我雄辩的 Report
模型关于这些自定义时间戳列名称.
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屋!