Use Model::withoutTimestamps() to update records during data migrations or internal status increments without altering their updated_at timestamps.
When running background data fixes, backfilling legacy columns, or incrementing internal counters (like view counts or sync hashes), updating a model modifies updated_at, which corrupts user-facing "Last Modified" dates.
The withoutTimestamps() method temporarily suspends automatic timestamp mutation.
Updating Models Without Timestamp Changes
use App\Models\Post;
// Updates the post without changing its updated_at column
Post::withoutTimestamps(function () use ($post, $migratedData) {
$post->update([
'legacy_sync_code' => $migratedData['code'],
'is_indexed' => true,
]);
});
On Individual Model Instances
$user->withoutTimestamps(function () use ($user) {
$user->update(['login_count' => $user->login_count + 1]);
});
Summary
- Preserves original
updated_attimestamps during maintenance updates. - Scoped strictly to the executed closure callback.
- Eliminates manual
$model->timestamps = falsestate toggling.
Related Tips
View all tips →Scope Pivot Table Queries with Closures in wherePivot() in Laravel 13.26
Laravel 13.26 allows wherePivot() and orWherePivot() to accept closures, enabling direct reuse of local scopes defined on custom Pivot models.
Simplify Chronological Query Sorting with latest() and oldest()
Replace verbose orderBy('created_at', 'desc') clauses with the clean latest() and oldest() query builder helpers.