1

in my controller

return view('admin.venue', ['cityList' => City::all()->toJson() ]);

and also i have tried it with

in my view

var allCities =  {{$cityList}};

and also i have tried

var allCities = JSON.parse({{$cityList}})
and
var allCities = JSON.parse('{{$cityList}}')

but it reply below error , i think the problem is about double quot. what is the correct way to use laravel json response in javascript

SyntaxError: invalid property id

var allCities = [{&-quot;id":1,&-quot;name":"cityname&-quot;,&-quot;p

0

1 Answer 1

2

Try to use {!! !!} instead of {{ }}:

var allCities =  {!! $cityList !!};

By default, Blade {{ }} statements are automatically sent through PHP's htmlentities function to prevent XSS attacks. If you do not want your data to be escaped, you may use the following syntax:

Hello, {!! $name !!}

https://laravel.com/docs/5.3/blade#displaying-data

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

Comments

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.