Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/cretueusebiu/laravel-javascript
Add JavaScript variables from Laravel
https://github.com/cretueusebiu/laravel-javascript
javascript laravel laravel-javascript
Last synced: 16 days ago
JSON representation
Add JavaScript variables from Laravel
- Host: GitHub
- URL: https://github.com/cretueusebiu/laravel-javascript
- Owner: cretueusebiu
- License: mit
- Created: 2016-07-24T20:11:10.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2017-06-14T07:19:09.000Z (over 7 years ago)
- Last Synced: 2024-10-10T23:53:55.127Z (about 1 month ago)
- Topics: javascript, laravel, laravel-javascript
- Language: PHP
- Homepage:
- Size: 9.77 KB
- Stars: 4
- Watchers: 4
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
laravel-javascript
> Add JavaScript variables from Laravel.
```php
ScriptVariables::add('user', Auth::user());
``````javascript
const user = window.config.user
```## Installation
Install the package via Composer:
```bash
composer require cretueusebiu/laravel-javascript
```Next, you need to register the service provider and facade:
```php
// config/app.php'providers' => [
...
Eusebiu\JavaScript\JavaScriptServiceProvider::class,
],'aliases' => [
...
'ScriptVariables' => Eusebiu\JavaScript\Facades\ScriptVariables::class,
],
```## Usage
In your controller:
```php
csrf_token(),
'currentUser' => auth()->user(),
];
});
}
}
```> Note that the variables must be passed via a closure.