Model::withoutTimestamps()
Execute operations without touching the updated_at column, useful for bulk imports and data migrations.
Overview
When you need to update models without modifying the updated_at timestamp, Model::withoutTimestamps() provides a clean way to do it.
Usage
use App\Models\Post;
Post::withoutTimestamps(function () {
Post::query()
->where('is_published', true)
->update(['view_count' => 0]);
});
When to Use
- Running data migrations or corrections
- Bulk importing records
- Syncing data from external sources where you want to preserve the original timestamps
- Resetting counters or computed fields