FooCollection::toArray() is ignored
Closed this issue · 5 comments
benascbr commented
Example
class MediaController {
public function index(): MediaCollection
}
class MediaCollection {
public function toArray()
{
return [
'items' => $this->resource->items(),
'foo' => 'bar',
];
}
}
It fails to read MediaCollection::toArray()
Expected generated response example:
[
'items' => [
MediaResource::toArray(),
...
],
'foo' => 'bar',
]
Actual:
[MediaResource::toArray(), ...]
Related links:
https://laravel.com/docs/11.x/eloquent-resources#resource-collections
I have v0.11.12 packge version
benascbr commented
P.S. Huge kudos for this package. It works almost out of the box for my current project
romalytvynenko commented
@benascbr please show your real code - I won't be able to help otherwise
benascbr commented
For sure. Creating example in https://github.com/dedoc/demo-scramble
benascbr commented
Resolved by changing
public function toArray($request): array|Arrayable|JsonSerializable
to
public function toArray($request): array
romalytvynenko commented
Still would be good to see the example, but if you call it a day - I agree!