@@ -59,21 +59,29 @@ public function toArray(): array
59
59
*/
60
60
protected static function resolvePropertyValue (string $ property , $ value )
61
61
{
62
- $ className = static ::getPropertyClassName ($ property );
62
+ $ type = static ::getPropertyType ($ property );
63
63
64
- if ($ className === null ) {
64
+ if ($ type === null ) {
65
65
return $ value ;
66
66
}
67
67
68
- if (is_array ($ value ) && is_a ( $ className , self ::class, true )) {
69
- return $ className :: fromArray ( $ value) ;
68
+ if ($ type === ' int ' && is_string ($ value ) && is_numeric ( $ value )) {
69
+ return ( int ) $ value ;
70
70
}
71
71
72
- if (is_array ( $ value ) && is_a ( $ className , ModelCollection::class, true )) {
73
- return $ className :: fromArray ( $ value) ;
72
+ if ($ type === ' string ' && is_int ( $ value )) {
73
+ return ( string ) $ value ;
74
74
}
75
75
76
- if (is_a ($ className , DateTimeInterface::class, true )) {
76
+ if (is_array ($ value ) && is_a ($ type , self ::class, true )) {
77
+ return $ type ::fromArray ($ value );
78
+ }
79
+
80
+ if (is_array ($ value ) && is_a ($ type , ModelCollection::class, true )) {
81
+ return $ type ::fromArray ($ value );
82
+ }
83
+
84
+ if (is_a ($ type , DateTimeInterface::class, true )) {
77
85
if (is_int ($ value ) || is_float ($ value )) {
78
86
return Carbon::createFromTimestamp ($ value );
79
87
}
@@ -86,7 +94,7 @@ protected static function resolvePropertyValue(string $property, $value)
86
94
return $ value ;
87
95
}
88
96
89
- protected static function getPropertyClassName (string $ property ): ?string
97
+ protected static function getPropertyType (string $ property ): ?string
90
98
{
91
99
$ reflectionClass = new ReflectionClass (static ::class);
92
100
$ reflectionProperty = $ reflectionClass ->getProperty ($ property );
0 commit comments