Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion src/Illuminate/Database/Eloquent/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -2421,7 +2421,15 @@ public function __sleep()
$this->classCastCache = [];
$this->attributeCastCache = [];

return array_keys(get_object_vars($this));
// 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)
);
}

/**
Expand Down