Skip to content
This repository was archived by the owner on Mar 3, 2025. It is now read-only.

Commit 3e21ee9

Browse files
committed
Fix JSON serialization
1 parent f7e23c2 commit 3e21ee9

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@
2424
"require": {
2525
"php": "^7.4",
2626
"illuminate/contracts": "^8.0",
27-
"spatie/data-transfer-object": "^2.5.0"
27+
"spatie/data-transfer-object": "^2.5.0",
28+
"thecodingmachine/safe": "^1.3"
2829
},
2930
"require-dev": {
3031
"orchestra/testbench": "^6.0",

src/Casts/DataTransferObject.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public function get($model, $key, $value, $attributes)
2626
return;
2727
}
2828

29-
return new $this->class(json_decode($value, true));
29+
return $this->class::fromJson($value);
3030
}
3131

3232
/**
@@ -46,6 +46,6 @@ public function set($model, $key, $value, $attributes)
4646
throw new InvalidArgumentException("Value must be of type [$this->class], array, or null");
4747
}
4848

49-
return json_encode($value->toArray());
49+
return $value->toJson();
5050
}
5151
}

0 commit comments

Comments
 (0)