diff --git a/src/Illuminate/Database/Eloquent/Concerns/HasTimestamps.php b/src/Illuminate/Database/Eloquent/Concerns/HasTimestamps.php index 2b6dfab6548e..47044238df16 100644 --- a/src/Illuminate/Database/Eloquent/Concerns/HasTimestamps.php +++ b/src/Illuminate/Database/Eloquent/Concerns/HasTimestamps.php @@ -199,7 +199,11 @@ public static function withoutTimestampsOn($models, $callback) try { return $callback(); } finally { - static::$ignoreTimestampsOn = array_values(array_diff(static::$ignoreTimestampsOn, $models)); + foreach ($models as $model) { + if (($key = array_search($model, static::$ignoreTimestampsOn, true)) !== false) { + unset(static::$ignoreTimestampsOn[$key]); + } + } } } diff --git a/tests/Database/DatabaseEloquentTimestampsTest.php b/tests/Database/DatabaseEloquentTimestampsTest.php index aa12f22f0266..9bc8d59b86a4 100644 --- a/tests/Database/DatabaseEloquentTimestampsTest.php +++ b/tests/Database/DatabaseEloquentTimestampsTest.php @@ -112,6 +112,12 @@ public function testWithoutTimestamp() $this->assertTrue($user->usesTimestamps()); $user->withoutTimestamps(function () use ($user) { + $this->assertFalse($user->usesTimestamps()); + + $user->withoutTimestamps(function () use ($user) { + $this->assertFalse($user->usesTimestamps()); + }); + $this->assertFalse($user->usesTimestamps()); $user->update([ 'email' => 'bar@example.com',