Foil icon indicating copy to clipboard operation
Foil copied to clipboard

Arraization(?) is turning my Eloquent collections into strings (not arrays)

Open martynbiz opened this issue 8 years ago • 1 comments

I'm passing in Eloquent Collections like so:

$engine->render('index/index', [
    'questions' => $questions,
);

If I var_export in the my controller class, the variable is set as an instance of Collection, but if I var_export within the template it's not an object, it's not an array even, but is a json_encoded string! I guess I could json_decode but is this the desired behaviour?

Also, how do I turn off Arraization for all templates? I might not wish to have this feature for now. Thanks

martynbiz avatar Oct 14 '16 22:10 martynbiz

@martynbiz Arraization is needed for autoescape. You can turn it off by disabling autoescape.

Regarding Collection convert to JSON encoded string this is very weird, indeed.

Eloquent collections have a toArray method that is called by arraization routine to arrayize it.

Then, each element of the array is converted to array (if not scalar) using same method, which should never end up in a JSON encoded string...

gmazzap avatar Oct 19 '16 09:10 gmazzap