PHPackages                             zdrojowa/laravel-blade-javascript - 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. [Templating &amp; Views](/categories/templating)
4. /
5. zdrojowa/laravel-blade-javascript

ActiveLibrary[Templating &amp; Views](/categories/templating)

zdrojowa/laravel-blade-javascript
=================================

A Blade directive to export variables to JavaScript

2.4.1(6y ago)01411MITPHPPHP ^7.2

Since Jun 5Pushed 6y agoCompare

[ Source](https://github.com/zdrojowa/laravel-blade-javascript)[ Packagist](https://packagist.org/packages/zdrojowa/laravel-blade-javascript)[ Docs](https://github.com/spatie/laravel-blade-javascript)[ RSS](/packages/zdrojowa-laravel-blade-javascript/feed)WikiDiscussions master Synced 2mo ago

READMEChangelog (1)Dependencies (4)Versions (22)Used By (1)

A Blade directive to export variables to JavaScript
===================================================

[](#a-blade-directive-to-export-variables-to-javascript)

[![Latest Version on Packagist](https://camo.githubusercontent.com/2635460750ade76cb0ea13f17ad0411afb5ed62c570ecbf29b8713a46f04a10a/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7370617469652f6c61726176656c2d626c6164652d6a6176617363726970742e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/spatie/laravel-blade-javascript)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![Build Status](https://camo.githubusercontent.com/a44419b72e4d192802e1dd1f3b04c8fedcc08b3b6e6812618a3ef2d9b01c24cd/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f7370617469652f6c61726176656c2d626c6164652d6a6176617363726970742f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/spatie/laravel-blade-javascript)[![Quality Score](https://camo.githubusercontent.com/22b85bae39bb0794b95c42b55e254ec37f30b67143a22627fa1ae3743a4c6b29/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f7370617469652f6c61726176656c2d626c6164652d6a6176617363726970742e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/spatie/laravel-blade-javascript)[![StyleCI](https://camo.githubusercontent.com/94d5fc004a426e499cb21cd7f501d60937302e210083f71cadf7ab22382e3126/68747470733a2f2f7374796c6563692e696f2f7265706f732f35393838363132382f736869656c64)](https://styleci.io/repos/59886128)[![Total Downloads](https://camo.githubusercontent.com/eaab496c5192b777da583953bf9fdd62c5c7813062a8b3b7d287d36e8704c9be/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f7370617469652f6c61726176656c2d626c6164652d6a6176617363726970742e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/spatie/laravel-blade-javascript)

This package contains a Blade directive to export values to JavaScript.

Here's an example of how it can be used:

```
@javascript('key', 'value')
```

The rendered view will output:

```
window['key'] = 'value';
```

So in your browser you now have access to a key variable:

```
console.log(key); //outputs "value"
```

Spatie is a webdesign agency based in Antwerp, Belgium. You'll find an overview of all our open source projects [on our website](https://spatie.be/opensource).

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

[](#installation)

You can install the package via composer:

```
composer require spatie/laravel-blade-javascript
```

The package will automatically register itself.

Optionally the config file can be published with

```
php artisan vendor:publish --provider="Spatie\BladeJavaScript\BladeJavaScriptServiceProvider" --tag="config"
```

This is the contents of the published config file:

```
return [

    /**
     * All passed values will be present in this JavaScript namespace. Set this to an empty string
     * to use the window object.
     */
    'namespace' => '',
];
```

If you want to customize the generated `` tag you can publish and override the used view.

```
php artisan vendor:publish --provider="Spatie\BladeJavaScript\BladeJavaScriptServiceProvider" --tag="views"
```

After this you can edit the published view `resources/views/vendor/bladeJavaScript/index.blade.php`. This is usefull to add the `type` or a CSP `nonce`.

Usage
-----

[](#usage)

With the package installed you can make use of a `@javascript` Blade directive.

```
@javascript('key', 'value')
```

The rendered view will output:

```
key = 'value';
```

You can also use a single argument:

```
@javascript(['key' => 'value'])
```

This will also output:

```
key = 'value';
```

When setting the namespace to eg `js` in the config file this will be the output:

```
window['js'] = window['js'] || {};js['key'] = 'value';
```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently.

Testing
-------

[](#testing)

```
$ composer test
```

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

Security
--------

[](#security)

If you discover any security related issues, please email  instead of using the issue tracker.

Postcardware
------------

[](#postcardware)

You're free to use this package, but if it makes it to your production environment we highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using.

Our address is: Spatie, Samberstraat 69D, 2060 Antwerp, Belgium.

We publish all received postcards [on our company website](https://spatie.be/en/opensource/postcards).

Credits
-------

[](#credits)

- [Freek Van der Herten](https://github.com/freekmurze)
- [Sebastian De Deyne](https://github.com/seb)
- [All Contributors](../../contributors)

This repository contains some code from the [laracasts/PHP-Vars-To-Js-Transformer](https://github.com/laracasts/PHP-Vars-To-Js-Transformer) package written by [Jeffrey Way](https://github.com/JeffreyWay).

Support us
----------

[](#support-us)

Spatie is a webdesign agency based in Antwerp, Belgium. You'll find an overview of all our open source projects [on our website](https://spatie.be/opensource).

Does your business depend on our contributions? Reach out and support us on [Patreon](https://www.patreon.com/spatie). All pledges will be dedicated to allocating workforce on maintenance and new awesome stuff.

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

31

—

LowBetter than 68% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity10

Limited adoption so far

Community17

Small or concentrated contributor base

Maturity67

Established project with proven stability

 Bus Factor1

Top contributor holds 69.8% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~62 days

Recently: every ~91 days

Total

20

Last Release

2441d ago

Major Versions

0.0.1 → 1.0.02016-06-07

1.1.0 → 2.0.02017-08-31

PHP version history (3 changes)0.0.1PHP ^7.0

2.2.2PHP ^7.1

2.3.0PHP ^7.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/f70a64950853e2b114b020b24898766bdee72043aeb30fb87c1dd2ea2d66772f?d=identicon)[zdrojowa](/maintainers/zdrojowa)

---

Top Contributors

[![freekmurze](https://avatars.githubusercontent.com/u/483853?v=4)](https://github.com/freekmurze "freekmurze (60 commits)")[![sebastiandedeyne](https://avatars.githubusercontent.com/u/1561079?v=4)](https://github.com/sebastiandedeyne "sebastiandedeyne (9 commits)")[![rubenvanassche](https://avatars.githubusercontent.com/u/619804?v=4)](https://github.com/rubenvanassche "rubenvanassche (5 commits)")[![rodrigopedra](https://avatars.githubusercontent.com/u/5470108?v=4)](https://github.com/rodrigopedra "rodrigopedra (2 commits)")[![Gummibeer](https://avatars.githubusercontent.com/u/6187884?v=4)](https://github.com/Gummibeer "Gummibeer (2 commits)")[![m1guelpf](https://avatars.githubusercontent.com/u/23558090?v=4)](https://github.com/m1guelpf "m1guelpf (1 commits)")[![RobinMalfait](https://avatars.githubusercontent.com/u/1834413?v=4)](https://github.com/RobinMalfait "RobinMalfait (1 commits)")[![akoepcke](https://avatars.githubusercontent.com/u/5311185?v=4)](https://github.com/akoepcke "akoepcke (1 commits)")[![serderovsh](https://avatars.githubusercontent.com/u/24723913?v=4)](https://github.com/serderovsh "serderovsh (1 commits)")[![blueclock](https://avatars.githubusercontent.com/u/586174?v=4)](https://github.com/blueclock "blueclock (1 commits)")[![codyphobe](https://avatars.githubusercontent.com/u/207072?v=4)](https://github.com/codyphobe "codyphobe (1 commits)")[![fridzema](https://avatars.githubusercontent.com/u/8180660?v=4)](https://github.com/fridzema "fridzema (1 commits)")[![jkudish](https://avatars.githubusercontent.com/u/260253?v=4)](https://github.com/jkudish "jkudish (1 commits)")

---

Tags

spatielaraveljavascriptbladedirectivelaravel-blade-javascript

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/zdrojowa-laravel-blade-javascript/health.svg)

```
[![Health](https://phpackages.com/badges/zdrojowa-laravel-blade-javascript/health.svg)](https://phpackages.com/packages/zdrojowa-laravel-blade-javascript)
```

###  Alternatives

[spatie/laravel-blade-javascript

A Blade directive to export variables to JavaScript

638855.8k9](/packages/spatie-laravel-blade-javascript)[spatie/laravel-blade-comments

Add debug comments to your rendered output

177325.5k](/packages/spatie-laravel-blade-comments)[radic/blade-extensions

Laravel package providing additional Blade extensions: foreach (with $loop data like twig), break, continue, set,array (multiline), etc

271321.7k5](/packages/radic-blade-extensions)[angus-mcritchie/blade-boost-directive

Lightning-Fast Blade Components with `@boost` Directive

3910.0k](/packages/angus-mcritchie-blade-boost-directive)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
