Remove " from json using laravel
Rendering JSON
Sometimes you may pass an array to your view with the intention of rendering it as JSON in order to initialize a JavaScript variable. For example:
<script>
var app = <?php echo json_encode($array); ?>;
</script>
However, instead of manually calling json_encode
, you may use the @json
Blade directive. The @json
directive accepts the same arguments as PHP's json_encode
function. By default, the @json
directive calls the json_encode
function with the JSON_HEX_TAG
, JSON_HEX_APOS
, JSON_HEX_AMP
, and JSON_HEX_QUOT
flags:
<script>
var app = @json($array);
var app = @json($array, JSON_PRETTY_PRINT);
</script>
You should only use the
@json
directive to render existing variables as JSON. The Blade templating is based on regular expressions and attempts to pass a complex expression to the directive may cause unexpected failures.
Source: documentation
You're escaping the data with {{ }}
automatically in Laravel 5. Use {!! $users !!}
instead.
in new laravel version you can use now @json($users)