Reputation: 407
I have serialize object returning from Controller to blade view in laravel like:
"a:3:{i:0;s:1:"2";i:1;s:1:"4";i:2;s:1:"6";}"
from my blade view I use this JS code block to get those value as array.
var branches = {{unserialize($preliminary->branches)}};
But in there I'm getting error saying
expression expected
any suggestions to solve this situation..?
Upvotes: 1
Views: 1152
Reputation: 47370
Run json_encode
on top of your unserialize
.
E.g.
var branches = {{json_encode(unserialize($preliminary->branches))}};
unserialize
is giving you a PHP object, which you are trying to inject directly into JS. By passing it through json_encode
you convert it to a string javascript can grok.
Upvotes: 1