diff --git a/src/SimpleDTO.php b/src/SimpleDTO.php index 28ec099..4f39567 100644 --- a/src/SimpleDTO.php +++ b/src/SimpleDTO.php @@ -13,6 +13,7 @@ use Illuminate\Http\UploadedFile; use Illuminate\Support\Collection; use Illuminate\Validation\ValidationException; +use JsonSerializable; use ReflectionClass; use ReflectionProperty; use UnitEnum; @@ -29,7 +30,7 @@ use WendellAdriel\ValidatedDTO\Exceptions\CastTargetException; use WendellAdriel\ValidatedDTO\Exceptions\MissingCastTypeException; -abstract class SimpleDTO implements BaseDTO, CastsAttributes +abstract class SimpleDTO implements BaseDTO, CastsAttributes, JsonSerializable { use DataResolver, DataTransformer; @@ -146,6 +147,14 @@ public function set($model, $key, $value, $attributes) return ''; } + /* + * JsonSerializable + */ + public function jsonSerialize(): mixed + { + return $this->toArray(); + } + /** * Maps the DTO properties before the DTO instantiation. */