PHPackages                             swisnl/laravel-javascript-data-response - 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. swisnl/laravel-javascript-data-response

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

swisnl/laravel-javascript-data-response
=======================================

JavaScript data response macro for Laravel

1.9.0(3mo ago)482.7k↓72.8%1MITPHPPHP ^8.1CI failing

Since May 18Pushed 3mo ago2 watchersCompare

[ Source](https://github.com/swisnl/laravel-javascript-data-response)[ Packagist](https://packagist.org/packages/swisnl/laravel-javascript-data-response)[ Docs](https://github.com/swisnl/laravel-javascript-data-response)[ RSS](/packages/swisnl-laravel-javascript-data-response/feed)WikiDiscussions master Synced 2d ago

READMEChangelog (10)Dependencies (8)Versions (13)Used By (0)

Laravel JavaScript data response
================================

[](#laravel-javascript-data-response)

[![PHP from Packagist](https://camo.githubusercontent.com/9b4e4dac2f3917eddc1c5c83f1591705fdba37b970baf6bdc86cf800051991e6/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f737769736e6c2f6c61726176656c2d6a6176617363726970742d646174612d726573706f6e73652e737667)](https://packagist.org/packages/swisnl/laravel-javascript-data-response)[![Latest Version on Packagist](https://camo.githubusercontent.com/d7fe6af8b95476c507fdb98559e77c527cff5c52a9a5bc0c279b6800ea29016e/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f737769736e6c2f6c61726176656c2d6a6176617363726970742d646174612d726573706f6e73652e737667)](https://packagist.org/packages/swisnl/laravel-javascript-data-response)[![Software License](https://camo.githubusercontent.com/9cfb8afceeb6e22ec088e4e047872a4bae9b45ed1bab7a2813878f6ba950bb85/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f737769736e6c2f6c61726176656c2d6a6176617363726970742d646174612d726573706f6e73652e737667)](LICENSE.md)[![Buy us a tree](https://camo.githubusercontent.com/195a3f79c3c2f91a69498ad26c1d8a7eeaf5771da0007200f409f5d438a515c4/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f54726565776172652d2546302539462538432542332d6c69676874677265656e2e737667)](https://plant.treeware.earth/swisnl/laravel-javascript-data-response)[![Build Status](https://camo.githubusercontent.com/b49589230bf740cbcd0a25a22acede9b599f084ba16d0a8f2e162161fa9056a6/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f737769736e6c2f6c61726176656c2d6a6176617363726970742d646174612d726573706f6e73652f74657374732e796d6c3f6c6162656c3d7465737473266272616e63683d6d6173746572)](https://github.com/swisnl/laravel-javascript-data-response/actions/workflows/tests.yml)[![Scrutinizer Coverage](https://camo.githubusercontent.com/a79ece098d0025e0fc453520392768ccf80b350f17b151607a48a538b74f8336/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f636f7665726167652f672f737769736e6c2f6c61726176656c2d6a6176617363726970742d646174612d726573706f6e73652e737667)](https://scrutinizer-ci.com/g/swisnl/laravel-javascript-data-response/?branch=master)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/f8e9baead0631dea31cb28ffdd9088ad2406bda739a4218c138094127c836b87/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f737769736e6c2f6c61726176656c2d6a6176617363726970742d646174612d726573706f6e73652e737667)](https://scrutinizer-ci.com/g/swisnl/laravel-javascript-data-response/?branch=master)[![Made by SWIS](https://camo.githubusercontent.com/8c541545402619860a7346c32a176d63a2b75eb8ebb85590d06a26b62417d260/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f2546302539462539412538302d6d6164652532306279253230535749532d2532333037333741392e737667)](https://www.swis.nl)

JavaScript data response macro for Laravel

Install
-------

[](#install)

```
$ composer require swisnl/laravel-javascript-data-response
```

Usage
-----

[](#usage)

This package adds a response macro (similar to Response::jsonp) which you can use just like any other response e.g.

```
Response::javascriptData('translations', ['en' => ['foo' => 'bar']]);
// or
response()->javascriptData('translations', ['en' => ['foo' => 'bar']]);
```

This will create the following response with the appropriate headers:

```
(function(){
    window["translations"] = {
        "en": {
            "foo": "bar"
        }
    };
})();
```

Configuration
-------------

[](#configuration)

The following is the default configuration provided by this package:

```
return [
    /*
    |--------------------------------------------------------------------------
    | JavaScript data Namespace
    |--------------------------------------------------------------------------
    |
    | The namespace to use for the JavaScript data using dot notation e.g. foo.bar will result in window["foo"]["bar"].
    |
    */

    'namespace' => '',

    /*
    |--------------------------------------------------------------------------
    | Default json_encode options
    |--------------------------------------------------------------------------
    |
    | The default options to use when json_encoding the data.
    | These will be ignored if options are provided
    | to the response macro/factory.
    |
    */

    'json_encode-options' => JSON_UNESCAPED_UNICODE,

    /*
    |--------------------------------------------------------------------------
    | Pretty print
    |--------------------------------------------------------------------------
    |
    | Should we add JSON_PRETTY_PRINT to the json_encode options.
    |
    */

    'pretty-print' => env('APP_ENV') !== 'production',

    /*
    |--------------------------------------------------------------------------
    | Default response headers
    |--------------------------------------------------------------------------
    |
    | The default headers for the JavaScript data response.
    | These will be ignored if headers are provided
    | to the response macro/factory.
    |
    */

    'headers' => [
        'Content-Type' => 'application/javascript; charset=utf-8',
    ],
];
```

### Publish Configuration

[](#publish-configuration)

If you would like to make changes to the default configuration, publish and edit the configuration file:

```
php artisan vendor:publish --provider="Swis\Laravel\JavaScriptData\ServiceProvider" --tag="config"
```

Change log
----------

[](#change-log)

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

Testing
-------

[](#testing)

```
$ composer test
```

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

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) and [CODE\_OF\_CONDUCT](CODE_OF_CONDUCT.md) for details.

Security
--------

[](#security)

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

Credits
-------

[](#credits)

- [Jasper Zonneveld](https://github.com/JaZo)
- [All Contributors](../../contributors)

License
-------

[](#license)

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

This package is [Treeware](https://treeware.earth). If you use it in production, then we ask that you [**buy the world a tree**](https://plant.treeware.earth/swisnl/laravel-javascript-data-response) to thank us for our work. By contributing to the Treeware forest you’ll be creating employment for local families and restoring wildlife habitats.

SWIS ❤️ Open Source
-------------------

[](#swis-heart-open-source)

[SWIS](https://www.swis.nl) is a web agency from Leiden, the Netherlands. We love working with open source software.

###  Health Score

56

—

FairBetter than 97% of packages

Maintenance80

Actively maintained with recent releases

Popularity36

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity79

Established project with proven stability

 Bus Factor1

Top contributor holds 90% 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 ~260 days

Recently: every ~375 days

Total

12

Last Release

106d ago

Major Versions

0.1.1 → 1.0.02018-09-07

PHP version history (5 changes)0.1.0PHP &gt;=7.0

1.1.0PHP &gt;=7.1.3

1.5.0PHP ^7.2|^8.0

1.6.0PHP ^7.4|^8.0

1.7.0PHP ^8.1

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/8734305?v=4)[SWIS](/maintainers/swisnl)[@swisnl](https://github.com/swisnl)

---

Top Contributors

[![JaZo](https://avatars.githubusercontent.com/u/3475007?v=4)](https://github.com/JaZo "JaZo (81 commits)")[![laravel-shift](https://avatars.githubusercontent.com/u/15991828?v=4)](https://github.com/laravel-shift "laravel-shift (9 commits)")

---

Tags

hacktoberfestjavascriptlaravelmacroresponseswisnllaravel-javascript-data-response

###  Code Quality

TestsPHPUnit

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/swisnl-laravel-javascript-data-response/health.svg)

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

###  Alternatives

[markwalet/nova-modal-response

A Laravel Nova asset for Modal responses on an action.

17878.9k](/packages/markwalet-nova-modal-response)[crumbls/layup

A visual page builder plugin for Filament 5 — Divi-style grid layouts with extensible widgets.

592.7k2](/packages/crumbls-layup)[team-nifty-gmbh/tall-datatables

Server-side rendered datatables for Laravel and Livewire

1320.9k4](/packages/team-nifty-gmbh-tall-datatables)[tomshaw/electricgrid

A feature-rich Livewire package designed for projects that require dynamic, interactive data tables.

119.4k](/packages/tomshaw-electricgrid)

PHPackages © 2026

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