PHPackages                             oriceon/larave-utilities - 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. oriceon/larave-utilities

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

oriceon/larave-utilities
========================

Transform your PHP to JavaScript

1.0.0(1y ago)02MITPHPPHP &gt;=5.5.0|&gt;=7.2.5|&gt;=8.0.0

Since Feb 27Pushed 1y agoCompare

[ Source](https://github.com/oriceon/PHP-Vars-To-Js-Transformer)[ Packagist](https://packagist.org/packages/oriceon/larave-utilities)[ RSS](/packages/oriceon-larave-utilities/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)Dependencies (2)Versions (2)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.

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

[](#installation)

Begin by installing this package through Composer.

```
composer require oriceon/laravel-utilities
```

> If you use Laravel 4: instead install `~1.0` of this package (and use the documentation for that release). For Laravel 5 (or non-Laravel), `~2.0` will do the trick!

### Laravel Users

[](#laravel-users)

For Laravel users, there is a service provider you can make use of to automatically register the necessary bindings.

> Laravel 5.5+ users: this step may be skipped, as we can auto-register the package with the framework.

```
// config/app.php

'providers' => [
    '...',
    'Laracasts\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
    ]);

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

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

Using the code above, you'll now be able to access `foo`, `user`, and `age` from your JavaScript.

```
console.log(foo); // bar
console.log(user); // User Obj
console.log(age); // 29
```

This package, by default, binds your JavaScript variables to a "footer" view, which you will include. For example:

```

    My Page

    @include ('footer') //
