2017 © Pedro Peláez
 

library laravel-javascript-data-response

JavaScript data response macro for Laravel

image

swisnl/laravel-javascript-data-response

JavaScript data response macro for Laravel

  • Thursday, May 24, 2018
  • by swisnl
  • Repository
  • 2 Watchers
  • 1 Stars
  • 1,161 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 3 Versions
  • 374 % Grown

The README.md

Laravel JavaScript data response

PHP from Packagist Latest Version on Packagist Software License Buy us a tree Build Status Scrutinizer Coverage Scrutinizer Code Quality Made by SWIS, (*1)

JavaScript data response macro for Laravel, (*2)

Install

``` bash $ composer require swisnl/laravel-javascript-data-response, (*3)


## Usage This package adds a response macro (similar to Response::jsonp) which you can use just like any other response e.g. ```php Response::javascriptData('translations', ['en' => ['foo' => 'bar']]); // or response()->javascriptData('translations', ['en' => ['foo' => 'bar']]);

This will create the following response with the appropriate headers:, (*4)

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

Configuration

The following is the default configuration provided by this package:, (*5)

``` php 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"]. | */, (*6)

'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',
],

];, (*7)


### Publish Configuration If you would like to make changes to the default configuration, publish and edit the configuration file: ``` bash php artisan vendor:publish --provider="Swis\Laravel\JavaScriptData\ServiceProvider" --tag="config"

Change log

Please see CHANGELOG for more information on what has changed recently., (*8)

Testing

bash $ composer test, (*9)

Contributing

Please see CONTRIBUTING and CODE_OF_CONDUCT for details., (*10)

Security

If you discover any security related issues, please email security@swis.nl instead of using the issue tracker., (*11)

Credits

License

The MIT License (MIT). Please see License File for more information., (*12)

This package is Treeware. If you use it in production, then we ask that you buy the world a tree to thank us for our work. By contributing to the Treeware forest you’ll be creating employment for local families and restoring wildlife habitats., (*13)

SWIS :heart: Open Source

SWIS is a web agency from Leiden, the Netherlands. We love working with open source software., (*14)

The Versions