Download the PHP package mikkellindblom/laravel-js-helper without Composer
On this page you can find all versions of the php package mikkellindblom/laravel-js-helper. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download mikkellindblom/laravel-js-helper
More information about mikkellindblom/laravel-js-helper
Files in mikkellindblom/laravel-js-helper
Package laravel-js-helper
Short Description Transform your PHP to JavaScript
License MIT
Informations about the package laravel-js-helper
Laravel js helper class
Installation
Begin by installing this package through Composer.
Ussage
When this provider is booted, you'll gain access to a helpful JavaScript
facade, which you may use in your controllers.
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.
This package, by default, binds your JavaScript variables to a "footer" view, which you will include. For example:
Naturally, you can change this default to a different view. See below.
Defaults
If using Laravel, there are only two configuration options that you'll need to worry about. First, publish the default configuration.
This will add a new configuration file to: config/javascript.php
.
bind_js_vars_to_this_view
You need to update this file to specify which view you want your new JavaScript variables to be prepended to. Typically, your footer is a good place for this.
If you include something like a layouts/partials/footer
partial, where you store your footer and script references, then make the bind_js_vars_to_this_view
key equal to that path. Behind the scenes, the Laravel implementation of this package will listen for when that view is composed, and essentially paste the JS variables within it.
js_namespace
By default, all JavaScript vars will be nested under the global window
object. You'll likely want to change this. Update the
js_namespace
key with the name of your desired JavaScript namespace. It can be anything. Just remember: if you change this setting (which you should),
then you'll access all JavaScript variables, like so:
Note
Run this artisan command after changing the view path.
License
View the license for this repo.