Skip to content

Commit 54cf9db

Browse files
authored
allow recursive Model::withoutTimestamps calls (#52768)
* allow recursive Model::withoutTimestamps calls * cs * cs
1 parent 2f3a005 commit 54cf9db

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

src/Illuminate/Database/Eloquent/Concerns/HasTimestamps.php

+5-1
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,11 @@ public static function withoutTimestampsOn($models, $callback)
199199
try {
200200
return $callback();
201201
} finally {
202-
static::$ignoreTimestampsOn = array_values(array_diff(static::$ignoreTimestampsOn, $models));
202+
foreach ($models as $model) {
203+
if (($key = array_search($model, static::$ignoreTimestampsOn, true)) !== false) {
204+
unset(static::$ignoreTimestampsOn[$key]);
205+
}
206+
}
203207
}
204208
}
205209

tests/Database/DatabaseEloquentTimestampsTest.php

+6
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,12 @@ public function testWithoutTimestamp()
112112
$this->assertTrue($user->usesTimestamps());
113113

114114
$user->withoutTimestamps(function () use ($user) {
115+
$this->assertFalse($user->usesTimestamps());
116+
117+
$user->withoutTimestamps(function () use ($user) {
118+
$this->assertFalse($user->usesTimestamps());
119+
});
120+
115121
$this->assertFalse($user->usesTimestamps());
116122
$user->update([
117123
'email' => '[email protected]',

0 commit comments

Comments
 (0)