PHPackages                             javascript/put-vars - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. javascript/put-vars

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

javascript/put-vars
===================

Transform your PHP to JavaScript

2.1.1(10y ago)163MITPHPPHP &gt;=5.5.0

Since Feb 25Pushed 10y ago1 watchersCompare

[ Source](https://github.com/duyluonglc/put-vars)[ Packagist](https://packagist.org/packages/javascript/put-vars)[ RSS](/packages/javascript-put-vars/feed)WikiDiscussions master Synced today

READMEChangelog (1)Dependencies (2)Versions (9)Used By (0)

Transform PHP Vars to JavaScript
================================

[](#transform-php-vars-to-javascript)

[![Build Status](https://camo.githubusercontent.com/a535269fe0268d0bcfff4148fc764bea9db61586797bd486bb8602dd5ea043ea/68747470733a2f2f7472617669732d63692e6f72672f6c61726163617374732f5048502d566172732d546f2d4a732d5472616e73666f726d65722e706e673f6272616e63683d6d6173746572)](https://travis-ci.org/laracasts/PHP-Vars-To-Js-Transformer)

Often, you'll find yourself in situations, where you want to pass some server-side string/array/collection/whatever to your JavaScript. Traditionally, this can be a bit of a pain - especially as your app grows.

This package simplifies the process drastically.

This source fo

Installation
------------

[](#installation)

Begin by installing this package through Composer.

```
{
    "repositories": [
        {
            "type": "vcs",
            "url": "https://github.com/duyluonglc/PHP-Vars-To-Js-Transformer"
        }
    ],
    "require": {
        ...............
		"javascript/utilities": "dev-master"
	}
}
```

### Laravel 5.1 Users

[](#laravel-51-users)

```
// config/app.php

'providers' => [
    '...',
    'JavaScript\Utilities\JavaScript\JavaScriptServiceProvider'
];
```

When this provider is booted, you'll gain access to a helpful `JavaScript` facade, which you may use in your controllers.

```
public function index()
{
    JavaScript::put([
        'foo' => 'bar',
        'user' => User::first(),
        'age' => 29
    ]);

    JavaScript::put('messages', ['hello', 'hi']);

    return View::make('hello');
}
```

> In Laravel 5, of course add `use JavaScript;` to the top of your controller.

Add render() to export variables to views. For example:

```

    My Page

    {!! JavaScript::render() !!} //
