Skip to content

Commit cf56959

Browse files
author
Pantea Marius-ciclistu
committed
POC for laravel/framework#31778 bulletproofing incrementOrDecrement and backport laravel pull/47450
1 parent 564f123 commit cf56959

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

illuminate/Database/Eloquent/Model.php

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -984,8 +984,12 @@ protected function incrementOrDecrement($column, $amount, $extra, $method)
984984

985985
$this->forceFill($extra);
986986

987-
if ($this->fireModelEvent('updating') === false) {
988-
return false;
987+
if (!$this->isDirty() || $this->fireModelEvent('updating') === false) {
988+
return 0;
989+
}
990+
991+
if ($this->isClassDeviable($column)) {
992+
$amount = (clone $this)->setAttribute($column, $amount)->getAttributeFromArray($column);
989993
}
990994

991995
return tap(
@@ -1271,18 +1275,18 @@ protected function performUpdate(Builder $query)
12711275
// Once we have run the update operation, we will fire the "updated" event for
12721276
// this model instance. This will allow developers to hook into these after
12731277
// models are updated, giving them a chance to do any special processing.
1274-
$dirty = $this->getDirtyForUpdate();
1278+
if ([] === $dirty = $this->getDirtyForUpdate()) {
1279+
return false;
1280+
}
12751281

1276-
if ([] !== $dirty) {
1277-
$this->setKeysForSaveQuery($query)->update($dirty);
1282+
$this->setKeysForSaveQuery($query)->update($dirty);
12781283

1279-
$this->syncChanges();
1284+
$this->syncChanges();
12801285

1281-
$this->tmpDirtyIfAttributesAreSyncedFromCashedCasts = null;
1282-
$this->tmpOriginalBeforeAfterEvents = $this->attributes;
1286+
$this->tmpDirtyIfAttributesAreSyncedFromCashedCasts = null;
1287+
$this->tmpOriginalBeforeAfterEvents = $this->attributes;
12831288

1284-
$this->fireModelEvent('updated', false);
1285-
}
1289+
$this->fireModelEvent('updated', false);
12861290

12871291
return true;
12881292
}

0 commit comments

Comments
 (0)