diff --git a/src/Illuminate/Database/Eloquent/SoftDeletes.php b/src/Illuminate/Database/Eloquent/SoftDeletes.php index fdca75ce11f3..0cd5446383de 100644 --- a/src/Illuminate/Database/Eloquent/SoftDeletes.php +++ b/src/Illuminate/Database/Eloquent/SoftDeletes.php @@ -60,9 +60,15 @@ protected function runSoftDelete() { $query = $this->newQueryWithoutScopes()->where($this->getKeyName(), $this->getKey()); - $this->{$this->getDeletedAtColumn()} = $time = $this->freshTimestamp(); + $time = $this->freshTimestamp(); - $query->update([$this->getDeletedAtColumn() => $this->fromDateTime($time)]); + $this->{$this->getDeletedAtColumn()} = $time; + $this->{$this->getUpdatedAtColumn()} = $time; + + $query->update([ + $this->getDeletedAtColumn() => $this->fromDateTime($time), + $this->getUpdatedAtColumn() => $this->fromDateTime($time) + ]); } /** diff --git a/tests/Database/DatabaseSoftDeletingTraitTest.php b/tests/Database/DatabaseSoftDeletingTraitTest.php index 1f255a8bbc25..077ee9717f26 100644 --- a/tests/Database/DatabaseSoftDeletingTraitTest.php +++ b/tests/Database/DatabaseSoftDeletingTraitTest.php @@ -19,7 +19,10 @@ public function testDeleteSetsSoftDeletedColumn() // $model->shouldReceive('newQuery')->andReturn($query = m::mock('StdClass')); $model->shouldReceive('newQueryWithoutScopes')->andReturn($query = m::mock('StdClass')); $query->shouldReceive('where')->once()->with('id', 1)->andReturn($query); - $query->shouldReceive('update')->once()->with(['deleted_at' => 'date-time']); + $query->shouldReceive('update')->once()->with([ + 'deleted_at' => 'date-time', + 'updated_at' => 'date-time' + ]); $model->delete(); $this->assertInstanceOf('Carbon\Carbon', $model->deleted_at); @@ -53,6 +56,7 @@ class DatabaseSoftDeletingTraitStub { use \Illuminate\Database\Eloquent\SoftDeletes; public $deleted_at; + public $updated_at; public function newQuery() { @@ -93,4 +97,9 @@ public function fromDateTime() { return 'date-time'; } + + public function getUpdatedAtColumn() + { + return defined('static::UPDATED_AT') ? static::UPDATED_AT : 'updated_at'; + } }