We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 66d4c92 commit 9c80cf4Copy full SHA for 9c80cf4
src/Illuminate/Database/Eloquent/Model.php
@@ -2421,7 +2421,15 @@ public function __sleep()
2421
$this->classCastCache = [];
2422
$this->attributeCastCache = [];
2423
2424
- return array_keys(get_object_vars($this));
+ // When serializing the model, we may accidentally catch up some virtual properties.
2425
+ // We will cast the model to a native array to skip them and then apply a function
2426
+ // to clean each of the property names which is miles faster than using a regex.
2427
+ return array_map(
2428
+ fn ($key) => $key[0] === "\0"
2429
+ ? substr($key, strpos($key, "\0", 1) + 1)
2430
+ : $key,
2431
+ array_keys((array) $this)
2432
+ );
2433
}
2434
2435
/**
0 commit comments