Reputation: 526
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
Upvotes: 1
Views: 92
Reputation: 163968
Try to use {!! !!}
instead of {{ }}
:
var allCities = {!! $cityList !!};
By default, Blade
{{ }}
statements are automatically sent through PHP'shtmlentities
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
Upvotes: 2