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

Admin   Laravel   171  2021-03-17 17:00:06

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...