Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

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

Awesome Lists containing this project

README

        

laravel-javascript

Latest Stable Version
Build Status
Total Downloads

> 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.