@@ -74,16 +74,17 @@ public function create(string $resourceClass, string $property, array $options =
7474
7575 // see https://laravel.com/docs/11.x/eloquent-mutators#attribute-casting
7676 $ builtinType = $ p ['cast ' ] ?? $ p ['type ' ];
77+ $ optional = $ p ['nullable ' ] || !is_null ($ p ['default ' ]);
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- 'array ' , 'encrypted:array ' => new Type (Type::BUILTIN_TYPE_ARRAY , $ p [ ' nullable ' ] ),
85- 'object ' , '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 ' => new Type (Type::BUILTIN_TYPE_INT , $ optional ),
80+ 'double ' , 'real ' => new Type (Type::BUILTIN_TYPE_FLOAT , $ optional ),
81+ 'boolean ' , 'bool ' => new Type (Type::BUILTIN_TYPE_BOOL , $ optional ),
82+ 'datetime ' , 'date ' , 'timestamp ' => new Type (Type::BUILTIN_TYPE_OBJECT , $ optional , \DateTime::class),
83+ 'immutable_datetime ' , 'immutable_date ' => new Type (Type::BUILTIN_TYPE_OBJECT , $ optional , \DateTimeImmutable::class),
84+ 'collection ' , 'encrypted:collection ' => new Type (Type::BUILTIN_TYPE_ITERABLE , $ optional , Collection::class, true ),
85+ 'array ' , 'encrypted:array ' => new Type (Type::BUILTIN_TYPE_ARRAY , $ optional ),
86+ 'object ' , 'encrypted:object ' => new Type (Type::BUILTIN_TYPE_OBJECT , $ optional ),
87+ default => new Type (\in_array ($ builtinType , Type::$ builtinTypes , true ) ? $ builtinType : Type::BUILTIN_TYPE_STRING , $ optional ?? true ),
8788 };
8889
8990 return $ propertyMetadata
0 commit comments