Looking to hire Laravel developers? Try LaraJobs

laravel-tojs maintained by yazvonov

Description
Transform PHP Vars to JavaScript for Laravel
Last update
2022/02/16 15:09 (dev-main)
License
Downloads
2 261
Tags

Comments
comments powered by Disqus

Transform PHP Vars to JavaScript for Laravel

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.