Replies: 1 comment 1 reply
-
When I try to reproduce this using this test it works: it('is weird sometimes', function () {
config()->set('data.wrap', 'data');
class TestData extends Data
{
public string $string;
#[DataCollectionOf(SimpleData::class)]
public array $array;
}
$dataA = TestData::from([
'string' => 'Hello World',
'array' => [
['string' => 'A'],
['string' => 'B'],
],
]);
$dataB = TestData::from([
'string' => 'Hello World',
'array' => [
['string' => 'A'],
['string' => 'B'],
],
]);
dd(
$dataA->toResponse(request())->getData(true),
(new PaginatedDataCollection(
TestData::class,
new LengthAwarePaginator([$dataA, $dataB], 2, 2)
))->toResponse(request())->getData(true)
);
}); DD: array:1 [
"data" => array:2 [
"string" => "Hello World"
"array" => array:1 [
"data" => array:2 [
0 => array:1 [
"string" => "A"
]
1 => array:1 [
"string" => "B"
]
]
]
]
] // /Users/ruben/Spatie/laravel-data/tests/DataTest.php:113
array:3 [
"data" => array:2 [
0 => array:2 [
"string" => "Hello World"
"array" => array:1 [
"data" => array:2 [
0 => array:1 [
"string" => "A"
]
1 => array:1 [
"string" => "B"
]
]
]
]
1 => array:2 [
"string" => "Hello World"
"array" => array:1 [
"data" => array:2 [
0 => array:1 [
"string" => "A"
]
1 => array:1 [
"string" => "B"
]
]
]
]
]
"links" => array:3 [
0 => array:3 [
"url" => null
"label" => "« Previous"
"active" => false
]
1 => array:3 [
"url" => "/?page=1"
"label" => "1"
"active" => true
]
2 => array:3 [
"url" => null
"label" => "Next »"
"active" => false
]
]
"meta" => array:11 [
"current_page" => 1
"first_page_url" => "/?page=1"
"from" => 1
"last_page" => 1
"last_page_url" => "/?page=1"
"next_page_url" => null
"path" => "/"
"per_page" => 2
"prev_page_url" => null
"to" => 2
"total" => 2
]
] |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
In my config I have wrappig enabled
I have a DTO like this
Now I have 2 controllers. 1 to get a specific order and 1 to get list of orders as such
But the result differs in the way it wraps the data.
Result for a single order
Result for multiple orders
While deliveries are in both cases an array of object, for a single order they are wrapped inside a data object but for a list of order they aren't while using the same OrderData class to return the data.
Beta Was this translation helpful? Give feedback.
All reactions