-
I enabled cast_and_transform_iterables in the config/data.php, I defined my array like this: /** @var array<int, RegionalValidityType> */
#[WithCast(RegionalValidityTypeCast::class)]
public array $validRegion; and in RegionalValidityTypeCast I implemented both interfaces But no matter what, the complete array will get passed to the "normal" I think I did everything according to the documentation. Is that feature not working correctly or did I miss something? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Ok I digged a little around in the code and learned the following things about Casts and iterables:
|
Beta Was this translation helpful? Give feedback.
Ok I digged a little around in the code and learned the following things about Casts and iterables:
Casts are only meant for casting into an object that does NOT extend the Data class!
For everything else you could use magic creation methods.
So my solution was to create a
public static function fromArray(array $value): self
method inside my abstract base classRegionalValidityType
.laravel-data seams to call the fromArray method with each item inside your iterable, so you can concentrate on a single item.