diff --git a/src/Illuminate/Database/Eloquent/Model.php b/src/Illuminate/Database/Eloquent/Model.php index 2d54b2c82e5e..44878f7bf880 100644 --- a/src/Illuminate/Database/Eloquent/Model.php +++ b/src/Illuminate/Database/Eloquent/Model.php @@ -2421,15 +2421,7 @@ public function __sleep() $this->classCastCache = []; $this->attributeCastCache = []; - // When serializing the model, we may accidentally catch up some virtual properties. - // We will cast the model to a native array to skip them and then apply a function - // to clean each of the property names which is miles faster than using a regex. - return array_map( - fn ($key) => $key[0] === "\0" - ? substr($key, strpos($key, "\0", 1) + 1) - : $key, - array_keys((array) $this) - ); + return array_keys(get_object_vars($this)); } /**