yazvonov/laravel-tojs

Transform PHP Vars to JavaScript for Laravel

v1.1 2022-02-16 14:09 UTC

This package is auto-updated.

Last update: 2025-07-16 21:26:51 UTC


README

How to install

composer require yazvonov/laravel-tojs

What It Does

This package Transform PHP Vars to JavaScript.

Put variables

ToJs::put([
    'variable1' => 'I want to see you in JavaScript',
    'variable2' => 'I want to see you in JavaScript too',
]);

Add tag @tojs to you blade template before <script>

@tojs

You will see this code on you page, and you can you it in JavaScript like window.laravel.variable1, window.laravel.variable2

<script>window.laravel = {"variable1":"I want to see you in JavaScript","variable2":"I want to see you in JavaScript too"};</script>

Configuration

You can change name in javascript, just add

TOJS_VAR_NAME=another_name 

to your .env file.

Security

If you discover any security-related issues, please email zvonovyo@gmail.com instead of using the issue tracker.

License

The MIT License (MIT). Please see License File for more information.