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"
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community