echo and blade escapes strings

Posted 1 year ago by eddieace

I have a codeblock that looks like this.

My problem is that everything after the var _globalObj row becomes green (the whole file)

    <script>
        var _globalObj = '<?php echo json_encode(array('_token'=> csrf_token())) ?>';
        var enableUrl = '{{url("admin/positions/enable-editor/" . $position->id)}}';
    </script>

I would like to have it something like this

    <script>
        var _globalObj = '{{ json_encode(array('_token'=> csrf_token())) }}';
        var enableUrl = '{{url("admin/positions/enable-editor/" . $position->id)}}';
    </script>

But for some reason blade escapes alot some json stuff like back slashes etc.

Any clues on how to solve this?

Please sign in or create an account to participate in this conversation.

Laracasts Mascot

Hi, Have We Met Yet?

Did you know that, in addition to the forum, Laracasts includes well over 1000 lessons on modern web development? All for the price of one lunch out per month.

Sign Me Up

Channels

Reply to

Use Markdown with GitHub-flavored code blocks.