Can I map Laravel's timestamps from:
created_at
to post_date
and post_date_gmt
?
updated_at
to post_modified
and post_modified_gmt
?
I'm migrating a Wordpress application to Laravel.
I'm accessing a copy of the Wordpress database using Laravel. The live version of the database is still in use so I don't want to change the schema.
The Posts table has post_date
, post_date_gmt
, post_modified
and post_modified_gmt
, but Laravel is expecting created_at
and updated_at
.
Is there anyway to change the column names that Laravel looks for?
I'd like Laravel to update the timestamps of all the columns that are already there.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With