How to use php array in json in laravel blade with @json

Laravel 7

Nicesnippets

33880

17-04-2020


Hello Dev,

In laravel blade template provide @json directive. now you don't use json_encode() function in laravel blade template. instead of manually calling json_encode, you can use the @json blade directive. without using json_encode function how to print php array in laravel blade.

In PHP


<script>

var app = <?php echo json_encode($myArray); ?>;

</script>

In Laravel Blade

<script>

var app = @json($myArray);

var app = @json($myArray, JSON_PRETTY_PRINT);

</script>

I hope it can help you...