HDInnovations / UNIT3D-Community-Edition

Private Torrent Tracker Built With Laravel, Livewire and AlpineJS.
GNU Affero General Public License v3.0
1.98k stars 379 forks source link

[Request] Swap `$model->update([..., 'updated_at' => DB::raw('updated_at')])` for `Model::withoutTimestamps(fn () => $model->update([...]))` #4298

Open Roardom opened 1 week ago

Roardom commented 1 week ago

Probably should refactor all of these at some point to use the idiomatic syntax.

Upvote & Fund

Fund with Polar

IonBazan commented 1 week ago

We can also do updateQuietly - this however prevents all model events/observers from being triggered (including Auditable).

Roardom commented 1 week ago

We can also do updateQuietly - this however prevents all model events/observers from being triggered (including Auditable).

Thanks for the alternative. In most cases that this hack is used, it's for bulk updates that don't send model events/observers anyways, so that shouldn't be an issue. However, if the goal is to not update the updated_at timestamp, then it's probably better to call a function named withoutTimestamps. We also generally try and avoid relying on too many model events/observers so that we can have more freedom to optimize our database queries.