Skip to content

Commit 8e8b562

Browse files
themsaidtaylorotwell
authored andcommitted
update timestamp on soft delete only when its used (#19627)
1 parent 3dbe83f commit 8e8b562

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

src/Illuminate/Database/Eloquent/SoftDeletes.php

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,17 @@ protected function runSoftDelete()
6262

6363
$time = $this->freshTimestamp();
6464

65+
$columns = [$this->getDeletedAtColumn() => $this->fromDateTime($time)];
66+
6567
$this->{$this->getDeletedAtColumn()} = $time;
66-
$this->{$this->getUpdatedAtColumn()} = $time;
6768

68-
$query->update([
69-
$this->getDeletedAtColumn() => $this->fromDateTime($time),
70-
$this->getUpdatedAtColumn() => $this->fromDateTime($time),
71-
]);
69+
if ($this->timestamps) {
70+
$this->{$this->getUpdatedAtColumn()} = $time;
71+
72+
$columns[$this->getUpdatedAtColumn()] = $this->fromDateTime($time);
73+
}
74+
75+
$query->update($columns);
7276
}
7377

7478
/**

tests/Database/DatabaseSoftDeletingTraitTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ class DatabaseSoftDeletingTraitStub
5757
use \Illuminate\Database\Eloquent\SoftDeletes;
5858
public $deleted_at;
5959
public $updated_at;
60+
public $timestamps = true;
6061

6162
public function newQuery()
6263
{

0 commit comments

Comments
 (0)