stri8ed / laravel-config-js
Laravel package for exposing configs in JS
Installs: 126
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
pkg:composer/stri8ed/laravel-config-js
Requires
- php: ^8.0
- ext-json: *
- laravel/framework: ^8.74|^9.0|^10.0|^11.0
Requires (Dev)
- orchestra/testbench: ^7.0 || ^8.0 || ^9.0
- phpunit/phpunit: ^9.5.10|^10.0
README
A Laravel package that exposes your Laravel configuration values to JavaScript.
Installation
composer require stri8ed/laravel-config-js
Usage
In your Blade views, use the @configJs directive to expose specific config values:
@configJs('app.name')
This creates a global laravelConfig() function that you can use in JavaScript:
// Get a single config value const appName = laravelConfig('app.name'); // With a default value const debug = laravelConfig('app.debug', false);
You can expose multiple config values:
@configJs(['app.name', 'app.env', 'services.api.key'])
Configuration
Optionally publish the config file to customize the JavaScript function name:
php artisan vendor:publish --tag="config-js"
License
MIT