Assign unserialize Laravel object to JS array

I have serialize object returning from Controller to blade view in laravel like:


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..?



Run json_encode on top of your unserialize.


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_encodeyou convert it to a string javascript can grok.


Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us

©2020 All rights reserved.