Laravel: Update created_at and updated_at timestamps manually

August 30th, 2022

If you want to manually set the created_at and updated_at values on a Laravel model you'll find that the updated_at field is overriden when the model is saved to the database.

To get around this you need to pass false to the save() method:

$user = App\Models\User::find(1);

$user->created_at = '2022-08-26 08:52:00';
$user->updated_at = '2022-08-26 08:52:00';
$user->save(['timestamps' => false]);

Previous →

Git Ignore File Mode