B
B
BonBon Slick2017-04-29 18:48:51
Laravel
BonBon Slick, 2017-04-29 18:48:51

How to disable quote escaping when passing PHP array to JavaScript?

Outputs a string with quotes. In a PHP array, these are regular strings.

var sgGames = {{ json_encode($suggestedGames) }};
// result
var sgGames = ["Counter-Strike","Half-Life",
// needed
 var test= ['Counter-Strike', 'Half-Life' ,'Counter-Strike',...];

PHP:
$suggestedGames = SteamGame::pluck('name')->toArray();
        return view('add_game', compact('suggestedGames'));

How to remove " ?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Ukolov, 2017-04-29
@BonBonSlick

Blade automatically escapes everything it outputs. You can disable shielding like this:
{!! json_encode($suggestedGames) !!};

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question