2424use Illuminate \Database \Eloquent \Relations \MorphMany ;
2525use Illuminate \Database \Eloquent \Relations \MorphToMany ;
2626use Illuminate \Support \Collection ;
27- use Symfony \Component \PropertyInfo \Type ;
27+ use Symfony \Component \TypeInfo \Type ;
28+ use Symfony \Component \TypeInfo \TypeIdentifier ;
2829
2930/**
3031 * Uses Eloquent metadata to populate the identifier property.
@@ -75,19 +76,23 @@ public function create(string $resourceClass, string $property, array $options =
7576 // see https://laravel.com/docs/11.x/eloquent-mutators#attribute-casting
7677 $ builtinType = $ p ['cast ' ] ?? $ p ['type ' ];
7778 $ type = match ($ builtinType ) {
78- 'integer ' => new Type (Type:: BUILTIN_TYPE_INT , $ p [ ' nullable ' ] ),
79- 'double ' , 'real ' => new Type (Type:: BUILTIN_TYPE_FLOAT , $ p [ ' nullable ' ] ),
80- 'boolean ' , 'bool ' => new Type (Type:: BUILTIN_TYPE_BOOL , $ p [ ' nullable ' ] ),
81- 'datetime ' , 'date ' , 'timestamp ' => new Type (Type:: BUILTIN_TYPE_OBJECT , $ p [ ' nullable ' ], \DateTime::class),
82- 'immutable_datetime ' , 'immutable_date ' => new Type (Type:: BUILTIN_TYPE_OBJECT , $ p [ ' nullable ' ], \DateTimeImmutable::class),
83- 'collection ' , 'encrypted:collection ' => new Type (Type::BUILTIN_TYPE_ITERABLE , $ p [ ' nullable ' ], Collection::class, true ),
84- 'encrypted:array ' => new Type (Type:: BUILTIN_TYPE_ARRAY , $ p [ ' nullable ' ] ),
85- 'encrypted:object ' => new Type (Type:: BUILTIN_TYPE_OBJECT , $ p [ ' nullable ' ] ),
86- default => new Type ( \in_array ($ builtinType , Type:: $ builtinTypes , true ) ? $ builtinType : Type::BUILTIN_TYPE_STRING , $ p [ ' nullable ' ] ?? true ),
79+ 'integer ' => Type:: int ( ),
80+ 'double ' , 'real ' => Type:: float ( ),
81+ 'boolean ' , 'bool ' => Type:: bool ( ),
82+ 'datetime ' , 'date ' , 'timestamp ' => Type:: object ( \DateTime::class),
83+ 'immutable_datetime ' , 'immutable_date ' => Type:: object ( \DateTimeImmutable::class),
84+ 'collection ' , 'encrypted:collection ' => Type:: collection (Type::object ( Collection::class) ),
85+ 'encrypted:array ' => Type:: builtin (TypeIdentifier:: ARRAY ),
86+ 'encrypted:object ' => Type:: object ( ),
87+ default => \in_array ($ builtinType , TypeIdentifier:: values () , true ) ? Type:: builtin ( $ builtinType) : Type::string ( ),
8788 };
8889
90+ if ($ p ['nullable ' ]) {
91+ $ type = Type::nullable ($ type );
92+ }
93+
8994 return $ propertyMetadata
90- ->withBuiltinTypes ([ $ type] )
95+ ->withNativeType ( $ type )
9196 ->withWritable ($ propertyMetadata ->isWritable () ?? true === $ p ['fillable ' ])
9297 ->withReadable ($ propertyMetadata ->isReadable () ?? false === $ p ['hidden ' ]);
9398 }
@@ -106,10 +111,13 @@ public function create(string $resourceClass, string $property, array $options =
106111 default => false ,
107112 };
108113
109- $ type = new Type ($ collection ? Type::BUILTIN_TYPE_ITERABLE : Type::BUILTIN_TYPE_OBJECT , false , $ relation ['related ' ], $ collection , collectionValueType: new Type (Type::BUILTIN_TYPE_OBJECT , false , $ relation ['related ' ]));
114+ $ type = Type::object ($ relation ['related ' ]);
115+ if ($ collection ) {
116+ $ type = Type::iterable ($ type );
117+ }
110118
111119 return $ propertyMetadata
112- ->withBuiltinTypes ([ $ type] )
120+ ->withNativeType ( $ type )
113121 ->withWritable ($ propertyMetadata ->isWritable () ?? true )
114122 ->withReadable ($ propertyMetadata ->isReadable () ?? true )
115123 ->withExtraProperties (['eloquent_relation ' => $ relation ] + $ propertyMetadata ->getExtraProperties ());
0 commit comments