diff --git a/packages/framework/src/Support/Concerns/Serializable.php b/packages/framework/src/Support/Concerns/Serializable.php index e799278074f..9fc66cb744a 100644 --- a/packages/framework/src/Support/Concerns/Serializable.php +++ b/packages/framework/src/Support/Concerns/Serializable.php @@ -17,9 +17,7 @@ trait Serializable /** Default implementation to dynamically serialize all public properties. Can be overridden for increased control. */ public function toArray(): array { - // Calling the function from a different scope means we only get the public properties. - - return get_object_vars(...)->__invoke($this); + return $this->automaticallySerialize(); } /** Recursively serialize Arrayables */ @@ -39,4 +37,12 @@ public function toJson($options = 0): string { return json_encode($this->jsonSerialize(), $options); } + + /** Automatically serialize all public properties. */ + protected function automaticallySerialize(): array + { + // Calling the function from a different scope means we only get the public properties. + + return get_object_vars(...)->__invoke($this); + } }