Avoid json_encode() and Use @json() Blade Directive

In this example i will discuss about json encode in laravel blade in details. Sometimes you may pass an array to your view with the intention of rendering it as JSON in order to initialize a JavaScript variable. That time what we do ? Normally we use json_encode() method as like below.


But do you know Laravel has awesome blade directive for json_encode. You can use @json for the same task what you do with json_encode. 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:


Hope it can help you.


Facebook Github
A web enthusiastic, self-motivated Full-Stack Web Developer from Dhaka, Bangladesh with experience in developing applications using Laravel Vue and React Js Application.