Change name of Laravel's created_at and updated_at

前端 未结 4 1184
眼角桃花
眼角桃花 2020-12-02 14:09

Can I map Laravel\'s timestamps from:

created_at to post_date and post_date_gmt?

updated_at to post

4条回答
  •  悲哀的现实
    2020-12-02 15:11

    The accepted answer may cause problems with updating timestamps unfortunately.

    You'd better override consts on your model:

    const CREATED_AT = 'post_date';
    const UPDATED_AT = 'post_modified';
    

    then methods getCreatedAtColumn and getUpdatedAtColumn will return post_date and post_modified respectively, but won't do any harm.

    For the other columns you need use events like @Oni suggested.

提交回复
热议问题