How to use php array in json in laravel blade with @json
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>
- How to Notifications With database Driver in Laravel 11?
- How to Send Email Via Notification in Laravel 11?
- How to Install and Configure Laravel 11 Debugbar?
- How to Like Dislike System in Laravel 11?
- How to Paginate a Model with Relationship in Laravel 11?
- Laravel 11 Upload Files to Amazon S3 Example
- Laravel 11 Send WhatsApp Messages Example
- Laravel 11 Rest API Authentication Using JWT Tutorial