yazvonov / laravel-tojs
Transform PHP Vars to JavaScript for Laravel
Installs: 1 953
Dependents: 0
Suggesters: 0
Security: 0
Stars: 10
Watchers: 6
Forks: 1
Open Issues: 0
Requires
- php: ^7.0|^8.0
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.