Need a little help with migration from DTO to data. Regarding ArrayCaster #266
-
This code is from Spatie\DataTransferObject. I am trying to convert it to laravel-data. I cannot figure out the equivalent to ArrayCaster, as show below the json object as named arrays. Any help would be appreciated. class PurchaseOrderObject extends CastableDataTransferObject
{
public ?int $order_number = 0;
/** @var LineItem[] */
#[CastWith(ArrayCaster::class, LineItem::class)]
public ?array $line_items;
}
class LineItem extends CastableDataTransferObject
{
public bool $checked;
public ?Children $children;
public ?Mapped $mapped;
}
class Children extends CastableDataTransferObject
{
/** @var Skus[] */
#[CastWith(ArrayCaster::class, Skus::class)]
public ?array $skus = [];
} {
"line_items": {
"35575": {
"mapped": {
"vendor_items": {
"58851": {
"sku": 58851,
"vendor": 4,
"checked": false,
"quantity": 1
}
}
},
"checked": true,
"children": {
"skus": {
"12485": {
"checked": true,
"vendor_items": {
"75366": {
"sku": 75366,
"vendor": 5,
"checked": true,
"quantity": 4
}
}
},
"12718": {
"checked": false,
"vendor_items": {
"76135": {
"sku": 76135,
"vendor": 5,
"checked": false,
"quantity": 6
},
"82287": {
"sku": 82287,
"vendor": 3,
"checked": false,
"quantity": 6
}
}
}
}
}
}
},
"order_number": 57048
} |
Beta Was this translation helpful? Give feedback.
Answered by
rubenvanassche
Nov 24, 2022
Replies: 1 comment 1 reply
-
Take a look at data collections and the |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
ccsliinc
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Take a look at data collections and the
DataCollectionOf
attribute. Alternatively, you could implement an array cast like the dto package but then you would lose a lot of the data package functionality.