Support the ongoing development of Laravel.io →
Input Views
Last updated 1 year ago.
0

Try using Collections.

Without looking too deeply into the source you can see that laravel is most like trying to call json_encode on your array directly.

If you wrap your array in a Collection which implements JsonableInterface it will try to call the toJson method on the Collection which will handle your objects better.

I'd expect the collections toJson to check if the childrens objects implement JsonableInterface and call toJson on them but looking at the source it in fact check if each child implements ArrayableInterface so as long as your contained object implements the ArrayableInterface it will work.

$data = new Illuminate\Support\Collection($data);
print_r($data);

"Fingers crossed"

Last updated 1 year ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.