cretueusebiu/laravel-javascript
Larablocks Analysis
cretueusebiu/laravel-javascript works with Laravel 5 (latest release 0.2.1, Mar 9, 2017), which reached end of life: no more fixes, even for security.
Recommendation checks
Not advisedNot advised: no release or commit in over 2 years.
- No release or commit in over 2 years
- Supports only Laravel 5, past end of life
- No release in the last 12 months (last: Mar 9, 2017)
- 11 downloads a month (needs 10,000)
- 4 GitHub stars (needs 100)
State
Likely abandoned- No release or commit in over 2 years.
- Last stable release: Mar 9, 2017.
- No releases in the last 12 months.
- First released: Jul 24, 2016.
- Monthly downloads: 11, down 90% from six months ago.
- 0 open issues on GitHub.
Data from Packagist and GitHub, checked by Larablocks on Nov 26, 2026.
| Install | |
|---|---|
composer require cretueusebiu/laravel-javascript |
|
| Latest Version: | 0.2.1 |
| PHP: | >=5.5.9 |
| Laravel: | 5 |
| License: | MIT |
| Last Updated: | Jun 14, 2017 |
| Links: | GitHub · Packagist |
laravel-javascript
Add JavaScript variables from Laravel.
ScriptVariables::add('user', Auth::user());
const user = window.config.user
Installation
Install the package via Composer:
composer require cretueusebiu/laravel-javascript
Next, you need to register the service provider and facade:
// config/app.php
'providers' => [
...
Eusebiu\JavaScript\JavaScriptServiceProvider::class,
],
'aliases' => [
...
'ScriptVariables' => Eusebiu\JavaScript\Facades\ScriptVariables::class,
],
Usage
In your controller:
<?php
namespace App\Http\Controllers;
use Eusebiu\JavaScript\Facades\ScriptVariables;
class HomeController extends Controller
{
public function home()
{
ScriptVariables::add('key', 'value');
ScriptVariables::add('data.user', User::first());
}
}
Next, in your blade view add:
{{ ScriptVariables::render() }}
Then in your JavaScript you can use:
const key = window.config.key
const user = window.config.data.user
To customize the namespace use ScriptVariables::render('custom').
Global Variables
You can register global variables (like the current user or csrf token) in your AppServiceProvider:
<?php
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
use Eusebiu\JavaScript\Facades\ScriptVariables;
class AppServiceProvider extends ServiceProvider
{
public function boot()
{
ScriptVariables::add(function () {
return [
'csrfToken' => csrf_token(),
'currentUser' => auth()->user(),
];
});
}
}
Note that the variables must be passed via a closure.
Related Packages
Powerful PHP database abstraction layer (DBAL) with many features for database s...
Laravel Serializable Closure provides an easy and secure way to serialize closur...
Cli error handling for console/command-line PHP applications.
Version History
| Version | Released | PHP | Laravel | License |
|---|---|---|---|---|
| 0.2.1 | >=5.5.9 | ^5.1 | MIT | |
| 0.2.0 | >=5.5.9 | ^5.1 | MIT | |
| 0.1.0 | MIT |