我可以从以下位置映射 Laravel 的时间戳吗:
created_at
to post_date
and post_date_gmt
?
updated_at
to post_modified
and post_modified_gmt
?
我正在将 Wordpress 应用程序迁移到 Laravel。
我正在使用 Laravel 访问 Wordpress 数据库的副本。数据库的实时版本仍在使用中,因此我不想更改架构。
帖子表有post_date
, post_date_gmt
, post_modified
and post_modified_gmt
,但 Laravel 期待created_at
and updated_at
.
有没有办法改变 Laravel 寻找的列名?
我希望 Laravel 更新已存在的所有列的时间戳。
不幸的是,接受的答案可能会导致更新时间戳问题。
您最好覆盖模型上的常量:
const CREATED_AT = 'post_date';
const UPDATED_AT = 'post_modified';
然后方法getCreatedAtColumn
and getUpdatedAtColumn
将返回post_date
and post_modified
分别,但不会造成任何伤害。
对于其他列,您需要使用 @Oni 建议的事件。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)