I just hit a snag with Eloquent's (Laravel 5.2.10) default timestamps. By default the $table->timestamps()
method gives you a created_at
and an updated_at
column in your table which are updated accordingly.
However, when I was trying some test entries, I noticed that when you update a record, the updated_at
field gets updated, as it should, but the created_at
field also gets updated: its hours stays at the created time, but the minutes and seconds get updated to match the updated_at
field.
If that was too wordy, here is an example:
+---------------------+---------------------+
| created_at | updated_at |
+---------------------+---------------------+
| 2016-01-13 17:13:27 | 2016-01-13 22:13:27 |
| 2016-01-13 16:14:41 | 2016-01-13 21:14:41 |
+---------------------+---------------------+
Notice that the minutes and seconds are the exact same for the created_at
and updated_at
field.
I tried to look through the Model
class where the timestamps are set, but it turns out the setCreatedAt()
method is indeed not called when just updating a record.
Why does this happen?
How do I prevent the created_at
field from changing? (more important)