|
19 | 19 | use ApiPlatform\Metadata\Property\Factory\PropertyMetadataFactoryInterface;
|
20 | 20 | use Illuminate\Database\Eloquent\Model;
|
21 | 21 | use Illuminate\Database\Eloquent\Relations\HasMany;
|
| 22 | +use Illuminate\Support\Collection; |
22 | 23 | use Symfony\Component\PropertyInfo\Type;
|
23 | 24 |
|
24 | 25 | /**
|
@@ -67,10 +68,15 @@ public function create(string $resourceClass, string $property, array $options =
|
67 | 68 | continue;
|
68 | 69 | }
|
69 | 70 |
|
| 71 | + // see https://laravel.com/docs/11.x/eloquent-mutators#attribute-casting |
70 | 72 | $builtinType = $p['cast'] ?? $p['type'];
|
71 | 73 | $type = match ($builtinType) {
|
72 |
| - 'datetime', 'date' => new Type(Type::BUILTIN_TYPE_OBJECT, $p['nullable'], \DateTime::class), |
| 74 | + 'double', 'real' => new Type(Type::BUILTIN_TYPE_FLOAT, $p['nullable']), |
| 75 | + 'datetime', 'date', 'timestamp' => new Type(Type::BUILTIN_TYPE_OBJECT, $p['nullable'], \DateTime::class), |
73 | 76 | 'immutable_datetime', 'immutable_date' => new Type(Type::BUILTIN_TYPE_OBJECT, $p['nullable'], \DateTimeImmutable::class),
|
| 77 | + 'collection', 'encrypted:collection' => new Type(Type::BUILTIN_TYPE_ITERABLE, $p['nullable'], Collection::class, true), |
| 78 | + 'encrypted:array' => new Type(Type::BUILTIN_TYPE_ARRAY, $p['nullable']), |
| 79 | + 'encrypted:object' => new Type(Type::BUILTIN_TYPE_OBJECT, $p['nullable']), |
74 | 80 | default => new Type(\in_array($builtinType, Type::$builtinTypes, true) ? $builtinType : Type::BUILTIN_TYPE_STRING, $p['nullable']),
|
75 | 81 | };
|
76 | 82 |
|
|
0 commit comments