Skip to content

Can't get to work IterableItemCast #854

Closed Answered by TiiFuchs
TiiFuchs asked this question in Q&A
Discussion options

You must be logged in to vote

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 class RegionalValidityType.

  • laravel-data seams to call the fromArray method with each item inside your iterable, so you can concentrate on a single item.

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by TiiFuchs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant