Skip to content

Commit

Permalink
allow recursive Model::withoutTimestamps calls (#52768)
Browse files Browse the repository at this point in the history
* allow recursive Model::withoutTimestamps calls

* cs

* cs
  • Loading branch information
m1guelpf authored Sep 12, 2024
1 parent 2f3a005 commit 54cf9db
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/Illuminate/Database/Eloquent/Concerns/HasTimestamps.php
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
}
}
}
}

Expand Down
6 changes: 6 additions & 0 deletions tests/Database/DatabaseEloquentTimestampsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' => '[email protected]',
Expand Down

0 comments on commit 54cf9db

Please sign in to comment.