1

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

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

1 Comment

Just make sure to replace {{}} with {!! !!}}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.