Skip to content

Commit 308e9b9

Browse files
committed
PHPORM-184 Use fixed key for temporary setting nested field
1 parent e8a8902 commit 308e9b9

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

src/Eloquent/Model.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@
4646
use function str_contains;
4747
use function str_starts_with;
4848
use function strcmp;
49-
use function uniqid;
5049
use function var_export;
5150

5251
/** @mixin Builder */
@@ -55,6 +54,8 @@ abstract class Model extends BaseModel
5554
use HybridRelations;
5655
use EmbedsRelations;
5756

57+
private const TEMPORARY_KEY = '__LARAVEL_TEMPORARY_KEY__';
58+
5859
/**
5960
* The collection associated with the model.
6061
*
@@ -271,12 +272,10 @@ public function setAttribute($key, $value)
271272
// Support keys in dot notation.
272273
if (str_contains($key, '.')) {
273274
// Store to a temporary key, then move data to the actual key
274-
$uniqueKey = uniqid($key);
275-
276-
parent::setAttribute($uniqueKey, $value);
275+
parent::setAttribute(self::TEMPORARY_KEY, $value);
277276

278-
Arr::set($this->attributes, $key, $this->attributes[$uniqueKey] ?? null);
279-
unset($this->attributes[$uniqueKey]);
277+
Arr::set($this->attributes, $key, $this->attributes[self::TEMPORARY_KEY] ?? null);
278+
unset($this->attributes[self::TEMPORARY_KEY], $uniqueKey);
280279

281280
return $this;
282281
}

0 commit comments

Comments
 (0)