Skip to content

Commit 9e28088

Browse files
authored
Add serialization support to SimpleDTO (#873)
Implemented __serialize and __unserialize methods in SimpleDTO to enable native PHP serialization. Added a unit test to verify that SimpleDTO instances can be serialized and unserialized correctly, including when instantiated from an Eloquent Model. Co-authored-by: Deeka Wong <8337659+huangdijia@users.noreply.github.com>
1 parent 90652e0 commit 9e28088

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

src/SimpleDTO.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,16 @@ public function __get(string $name): mixed
107107
return $this->{$name} ?? null;
108108
}
109109

110+
public function __serialize(): array
111+
{
112+
return $this->jsonSerialize();
113+
}
114+
115+
public function __unserialize(array $data): void
116+
{
117+
$this->__construct($data);
118+
}
119+
110120
/**
111121
* Cast the given value to a DTO instance.
112122
*

0 commit comments

Comments
 (0)